gpt4 book ai didi

javascript - 在没有 jQuery 的情况下禁用 pre IE9 中的按钮

转载 作者:行者123 更新时间:2023-11-30 12:08:54 24 4
gpt4 key购买 nike

如何禁用 IE9 之前的 Internet Explorer 中的按钮?我尝试了以下方法:

        var button = document.getElementById('myButton');
if (button != 'undefined' && button != null)
button.disabled = true;

最佳答案

XML/HTML 属性值是字符串,因此不接受 bool 值“true”和“false”;它们没有特殊意义

试试看:

var button = document.getElementById('myButton');
if (button != 'undefined' && button != null)
button.disabled = 'disabled'; //'disabled' not false

为什么?

StackOverflow答案总结得很好,关于为什么你不能使用 bool 值:https://stackoverflow.com/a/7089749/4206206

In SGML, an attribute may be minimized so that its value alone is short for both the name and the value, with the only possible value for the attribute in this case obviously being the attribute's own name. HTML uses this for boolean attributes, where the presence or absence of the attribute is what's meaningful, and its value is irrelevant.

关于javascript - 在没有 jQuery 的情况下禁用 pre IE9 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34399762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com