Which HTMLElement property change generates DOMAttrModified?

左心房为你撑大大i 提交于 2019-12-11 10:09:05

问题


I have a question about DOMAttrModified. Which changes to an HTML Element properties triggers the DOMAttrModified event (specifically interested in Firefox, but an answer that applies to other browsers might suffice too)?

I have the following test case :

        var elem = document.createElement('input');
        document.body.appendChild(elem);

        elem.id    = 'inputId';      // triggers DOMAttrModified
        elem.type  = 'text';         // triggers DOMAttrModified
        elem.value = 'inputValue';   // DOES NOT trigger DOMAttrModified
        elem.lang  = 'en';           // triggers DOMAttrModified

If I change elem.value to elem.defaultValue, then a DOMAttrModified does get triggered. Is there a comprehensive list somewhere? So far I have found HTMLInputElement's 'value' and 'checked' and HTMLOptionElement's 'selected' property not trigerring DOMAttrModified. Are there any other?

The answer at DOMAttrModified visual attributes does NOT seem to be completely correct, as 'value' is also an attribute.

Thanks, Sunil


回答1:


The DOM value property doesn't change the HTML value markup attribute. The DOM defaultValue does. DOMAttrModified fires when markup attributes change, so on setAttribute/removeAttribute calls and on any property set that changes an attribute.




回答2:


Please also note that NO DOMAttrModified events will be fired when the 'disabled' attribute is set. So if your event is not firing, that could be the reason. This also goes for the IE-only 'onPropertyChange' event.



来源:https://stackoverflow.com/questions/9919594/which-htmlelement-property-change-generates-domattrmodified

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!