2012-06-07 31 views
4

我有我的網頁上,看起來像這樣的輸入(按鈕):輸入在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中灰顯。

回答

6

如果您使用jQuery 1.6 +你應該使用.prop因爲「禁用」是的財產element

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

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

+0

這樣做的伎倆 – mtmurdock

1

由於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 
相關問題