日期:2014-05-16 浏览次数:20448 次
<div id="panel"><div/>
document.getElementById("panel").innerHTML = "sdfsd";
function Element(value, domEL){ this.domEl = domEL; this.domEl.getValue = function() { return value; }; this.domEl.setValue = function(newValue){ var isChange = false || value!=newValue; value = newValue; if(isChange && this.onValueChange) this.onValueChange(); }; this.domEl.buttonObj = this; this.domEl.onValueChange=this.valueChangeHandler; } Element.prototype.valueChangeHandler=function(){ var buttonObj = this.buttonObj; alert('value is changed to '+ buttonObj.domEl.getValue()); } var b = new Element(1, document.getElementById("panel"));
var Element = function(obj){ this.element = obj; return this; } Element.prototype.innerHTML = function(txt, callBack) { var _arg = []; var _len = arguments.length; for(var i = 0; i < _len; i++) { _arg[i] = arguments[i]; } var _oldTxt = this.element.innerHTML; this.element.innerHTML = _arg.shift(); _arg.shift(); callBack.apply(window, [_oldTxt, txt].concat(_arg)); } var $Element = function(id) { var _obj = (typeof(id) == 'string')? document.getElementById(id) : id; return new Element(_obj); } function alertIt(oldTxt, newTxt, str) { alert(str); } $Element('box').innerHTML('ddd', alertIt, '内容改变了!');
------解决方案--------------------
目前DOM的标准没有暴露出这样一个接口,个人感觉,楼上的重载innerHTML的方式,要比setInterval好,最好还是修改下设计或者算法,这个需求还是有点怪。