问题描述
我有一个关于DOMAttrModified的问题。对HTML元素属性进行的哪些更改会触发DOMAttrModified事件(特别感兴趣的是Firefox,但是适用于其他浏览器的答案也可能足够)?我有以下测试case:
标记属性。 DOM defaultValue 没有。 DOMAttrModified 会在标记属性发生变化时触发,所以 setAttribute / removeAttribute 调用以及任何改变属性的属性集。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 DOMAttrModifiedIf 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
解决方案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.
这篇关于哪个HTMLElement属性更改生成DOMAttrModified?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!