我已经(成功)在我的旧 Vista 机器上使用了以下内容:
var isIE = isInternetExplorer();
$("#divTablesButton" + (isIE ? "" : " :input"))
.attr( "disabled", this.m_Array1.length === this.m_Array2.length ? true : false );
其中 divTablesButton
是一个按钮,isInternetExplorer
是函数(似乎仍然工作正常):
function isInternetExplorer() {
return ( getInternetExplorerVersion() < 0 ? false : true );
};
function getInternetExplorerVersion() {
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
return rv;
};
但现在我注意到这在我的带有最新版本 IE 和 Chrome 的 Win 8.1 计算机上不起作用。
有人知道怎么回事吗?需要澄清的是,attr("disabled"
位是错误的。按钮不会禁用。
最佳答案
您使用的 jQuery 版本是什么?在 >1.6 版本中,他们希望人们使用 .prop()
而不是 .attr()
来获取 disabled
、required< 等属性
、checked
等( bool 值)。 This older SO question会比我更好地解释。
尝试使用 prop()
代替,如下所示。此外,您还可以删除一段代码。您已经编写了语句 variable_a === variable_b ?真:假
。 variable_a === variable_b
的结果将始终为 true
或 false
,因此您不需要 ? true : false
部分。
var isIE = isInternetExplorer();
$("#divTablesButton" + (isIE ? "" : " :input")).prop("disabled", this.m_Array1.length === this.m_Array2.length);
希望这有帮助。
关于javascript - jQuery 禁用不再在我的 Win8.1 机器上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27000983/