哪个HTMLElement属性更改生成DOMAttrModified? [英] Which HTMLElement property change generates DOMAttrModified?

查看:183
本文介绍了哪个HTMLElement属性更改生成DOMAttrModified?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于DOMAttrModified的问题。对HTML元素属性进行的哪些更改会触发DOMAttrModified事件(特别感兴趣的是Firefox,但是适用于其他浏览器的答案也可能足够)?

我有以下测试case:

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

elem.id ='inputId'; //触发DOMAttrModified
elem.type ='text'; //触发DOMAttrModified
elem.value ='inputValue'; //不会触发DOMAttrModified
elem.lang ='en'; //触发DOMAttrModified

如果将elem.value更改为elem.defaultValue,则DOMAttrModified会被触发。是否有一个全面的清单?到目前为止,我已经找到HTMLInputElement的值和检查和HTMLOptionElement的选择属性不会引发DOMAttrModified。有没有其他的?



DOMAttrModified视觉属性似乎并不完全正确,因为价值也是一个属性。

谢谢,
Sunil

解决方案 标记属性。 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 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

解决方案

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆