2012-08-28 176 views
0

下面的代碼是不是在IE.I工作需要鍍鉻,火狐狸和IE來解決這個如何禁用點擊事件按鈕?

button.Attributes["disabled"] = "disabled"; 
+2

你在javaScript中還是在服務器端? – harry180

+0

這個對象生成的html源代碼是什麼? – reporter

+0

什麼?作爲@ harry180說,它殼更好,使其與js – Cynede

回答

6

你只需要設置它的Enabled propertyfalse在服務器端:

button.Enabled = false; 

編輯:如果button是一個鏈接,它不會在其他瀏覽器比IE的工作,看看下面的鏈接:http://www.aspnetajaxtutorials.com/2009/05/how-to-enable-or-disable-linkbutton-in.html

<asp:LinkButton ID="lnkTest" runat="server" CommandArgument="1" CommandName="1x" 
OnClick="lnkTest_Click">Test</asp:LinkButton> 

風格啓用和禁用是

<style> 
.LnkEnabled 
{ 
cursor: pointer; 
} 
.LnkDisabled 
{ 
cursor: default; 
color: Gray; 
} 
</style> 

javascript函數

<script language="javascript"> 
function EnableLinkButton(ID,flag) 
{ 
    document.getElementById(ID).onclick=function(){return flag;}; 
    if(!flag) 
    { 
     document.getElementById(ID).setAttribute("disabled","disabled"); 
     document.getElementById(ID).className="LnkDisabled"; 
    } 
    else 
    { 
     document.getElementById(ID).setAttribute("disabled",""); 
     document.getElementById(ID).className="LnkEnabled"; 
    } 
} 
EnableLinkButton('<%= lnkTest.ClientID %>',false); 
</script> 

EDIT2:如果不工作(沒有測試過),你也可以試試這個:

button.Attributes.Add("onClick", "return !this.disabled;") 
+0

沒有這已經不能解決我的問題 – Nandhu

+0

@Nandha:編輯我的答案。 –

0
$('#button_id').attr('disabled', 'disabled'); 
+0

與在服務器端生成的'Enabled = false'或'Attributes [「disabled」] =「disabled」'相同。但它顯然不適用於其他瀏覽器與IE瀏覽器的鏈接(錨標籤):'this is not disabled in FF' –

1
button.Attributes.Add("disabled", "true"); 
+0

對不起,沒有工作........... – Nandhu

+0

Ohk ..現在..我做了一些變化。 – ygssoni