在没有jQuery的情况下禁用IE9之前版本中的按钮

Disable button in pre IE9 without jQuery

本文关键字:版本 按钮 IE9 jQuery 情况下      更新时间:2023-09-26

如何在ie9之前禁用internet explorer中的按钮?我尝试了以下方法:

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

XML/HTML属性值是字符串,因此布尔值"true"answers"false"将不被接受;它们没有特殊的含义

试试:

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

为什么

这个StackOverflow的答案很好地总结了它,关于为什么不能使用布尔值:https://stackoverflow.com/a/7089749/4206206

在SGML中,一个属性可以被最小化,使得它的值单独是名称和值的缩写,在这种情况下,该属性唯一可能的值显然是该属性自己的名称。HTML将其用于布尔属性,在布尔属性中,属性的存在或不存在是有意义的,其值是无关的。