2012-08-28 179 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