如果不支持propertychange事件,就使用这个,或者更高端的MutationObserver.
var root = document.documentElement supportDOMAttrModified = root.addEventListener ? ( function () { var fn, f = false , id = root.id; fn = function () { root.removeEventListener( 'DOMAttrModified' , fn, false ); supportDOMAttrModified = true ; root.id = id; //还原它 }; root.addEventListener( 'DOMAttrModified' , fn, false ); root.id = 'mass' ; //更新属性 f = root.id != 'mass' ; root.id = id; //无论如何也还原它 return f; })() : false |
标签: javascript