我使用以下 Javascript 在单击后禁用按钮:
var c = 0;
function DisableClick(target) {
var objName = target;
document.getElementById(objName).disabled = true;
c = c + 1;
msg = 'Please Wait...(' + c + ')!';
document.getElementById(objName).value = msg;
var t = setTimeout('DisableClick()', 1000);
}
<asp:Button ID="btnLogin" runat="server" CssClass="cssLoginButton blue" Text="Log in" ToolTip="Log in" ValidationGroup="UserLogin" onclick="btnLogin_Click" OnClientClick="DisableClick('btnLogin')" />
我的 Javascript 出现此错误:
Microsoft JScript runtime error: Unable to set value of the property 'disabled': object is null or undefined
我该如何解决这个问题?
最佳答案
您可以在 javascript 函数中传递单击的按钮对象。如果不需要回发则返回 false。
改变
OnClientClick="DisableClick('btnLogin')"
至
// the DisableClick make a loop, so make the return here.
OnClientClick="DisableClick(this);return false;"
function DisableClick(target) {
target.disabled = true;
c = c + 1;
msg = 'Please Wait...(' + c + ')!';
target.value = msg;
// The DisableClick needs the target parametre, so send it again
// but need to keep it here for work.
var me = target;
var t = setTimeout(function(){DisableClick(me);}, 1000);
}
关于Javascript 禁用 asp.net 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13539056/