javascript - 这是IE中的错误吗?

标签 javascript internet-explorer internet-explorer-11

我正在从我的应用程序中复制一个场景,

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 应该忽略这样的属性吗?

JSFiddle

最佳答案

这并不能断定这是一个错误,但可以更深入地了解事情。

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/

相关文章:

javascript - 如何在渲染器进程中使用 window.open 在 Electron 中打开新窗口?

javascript - 如何使用 jquery 在悬停/鼠标悬停时淡入 div?

javascript - Angular (1.2) $sce 阻止我的 blob src

css - IE8 在错误的位置寻找来自 css 的图像

header - “ header ”在 IE11 中未定义

css - 宽度不在 IE11 中换行

html - maxlength 和 minlength 不验证 IE 中的 HTML 文本框

javascript - Jquery 不显眼的验证 : add class to label of invalid field

jquery - if 条件 : if the browser is IE and IE browser version is older than 9

javascript - 有人知道为什么 "x".split(/(x)/).length 在 IE 中返回 0 吗?