我正在从我的应用程序中复制一个场景,
HTML:
<input type='text' disabled='true' />
<input type='text' disabled='true' />
<input type='text' disabled='true' />
<input type='text' disabled='true' />
<div disabled='true'>
<input type='text' disabled='true' />
</div>
<input type='text' disabled='true' />
<p id='test'></p>
我想在单击按钮时启用这些元素,等效的 js,
var x = document.querySelectorAll('input[type="text"]');
var p = document.querySelector('#test');
[].slice.call(x);
for (var i = 0; i < x.length; i++) {
p.innerHTML += x[i].getAttribute("disabled") + " ";
x[i].removeAttribute("disabled");
}
在所有浏览器中都能正常工作,
但是,在 IE 中,父级禁用的 input
显示为禁用,但实际上并非如此。
关于为什么会发生这种情况的任何解释?
我确实意识到 disabled
不是 div
的有效属性,但是 IE 应该忽略这样的属性吗?
最佳答案
这并不能断定这是一个错误,但可以更深入地了解事情。
http://www.techtamasha.com/the-disabled-attribute-in-internet-explorer/256
直接来自那篇文章:
‘disabled’ attribute only works on BUTTON INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA tags and the general policy of browser is if you use any attribute which are not authorized to use in tag then browsers neglect them but they can be accessed using javascript. But IE isn’t that kind in this case. If you apply ‘disabled’ on div tag, IE takes it seriously and makes div tag disabled. So what this means is that we not only have any control event on div but also according to “This attribute is inherited but local declarations override the inherited value.” rule in W3C disable specification, IE applies disabled attribute on nested elements in div tag. So be careful.
关于javascript - 这是IE中的错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22681159/