输入在IE中显示为禁用,但未被禁用

问题描述:

我有我的网页上,看起来像这样的输入(按钮):输入在IE中显示为禁用,但未被禁用

<input id="the-button" type="submit" class="btn" value="Click me!"> 

我覆盖表单提交的动作,所以我可以在退房前的几件事实际上提交表格。在这之前,我禁用了该按钮,因此用户不会再次单击它,以便他们可以看到该页面正在工作。

$("#the-button").attr("disabled", true); 

如果我决定不提交表单,我重新启用按钮。

$("#the-button").attr("disabled", false); 

这将按预期在Chrome/Firefox中,但在IE8 出现按钮被禁用,但你仍然可以点击它。期望的行为是看起来启用,但它在IE中灰显。

如果您使用jQuery 1.6 +你应该使用.prop因为“禁用”是的财产element

$("#the-button").prop("disabled", true); 
$("#the-button").prop("disabled", false); 

http://api.jquery.com/prop/

+0

这样做的伎俩 – mtmurdock

由于Wirey说的是使用prop最好的办法,然而,如果你坚持使用老版本的jQuery,你可以“镜像”IE语句,例如:

$("#the-button").attr("disabled", ""); // Enabled 
$("#the-button").attr("disabled", "disabled"); // Disabled 

ReadOnly(显然在文本框之类)

$("#the-button").attr("readonly", ""); // Read Write 
$("#the-button").attr("readonly", "readonly"); // Read Only