如何禁用ASP.NET中的按钮

时间:2015-01-09 05:35:52

标签: javascript asp.net button

我的图片上有一个onclick代码,用于禁用我的表单上看起来像这样的按钮

<img alt="" src="images/search-icon.png" width="16" height="16" style="display: inline;height:16px;cursor:pointer; width: 16px;" onclick="DisableButton('<%=btnSave.ClientID %>');" />

然后在我的javascript上我有这样的代码

function DisableButton(bSave) {
document.getElementById(bSave).attributes("Enabled", false);
}

问题是它无法正常工作,每次点击图片都没有任何反应。我的代码有错误吗?请帮我解决这个问题。提前谢谢。

3 个答案:

答案 0 :(得分:1)

使用&#39;禁用&#39;

document.getElementById(bSave).disabled = true;

http://www.w3schools.com/jsref/prop_html_disabled.asp

清除禁用与禁用歧义。

答案 1 :(得分:0)

这是代码:

 document.getElementById(bSave).disabled = true;

或者

document.getElementById('<%= btnSave.ClientID %>').disabled = true;

答案 2 :(得分:0)

请使用此功能   在你的脚本中:

document.getElementById(bSave).disabled = true;

如果你正在使用jquery那么

 $("#"bSave).prop("disabled",true);