简体   繁体   English

使用javascript禁用/启用asp.net linkbutton

[英]disable / enable asp.net linkbutton using javascript

I need to be able to enable and disable a linkbutton using javascript as part of a custom validator that I'm writing. 我需要能够使用javascript启用和禁用链接按钮作为我正在编写的自定义验证器的一部分。

I discovered that setting "disabled=true" will disable a standard button, but it does nothing to a linkbutton. 我发现设置“disabled = true”将禁用标准按钮,但它对链接按钮没有任何作用。

After mucking about in JQuery I discovered that the following will actually disable the button: 在使用JQuery后,我发现以下内容实际上会禁用该按钮:

$(button).click( function() { return false; }

Where button is a reference to the object. 其中button是对对象的引用。 That works well. 这很好用。 However, I can't for the life of me work out how to re-enable it! 但是,我不能为我的生活做出如何重新启用它! Neither of these seem to work: 这些似乎都不起作用:

$(button).click( function() { return true; }
$(button).click( function() { }

If anyone could either point me in the right direction to re-enable my button, or suggest a better way of disabling the button, It'd be appreciated. 如果有人可以向我指出正确的方向以重新启用我的按钮,或提出禁用该按钮的更好方法,我们将不胜感激。

Chers, Matt Chers,马特

I think you have to unbind the first event first. 我认为您必须先取消绑定第一个活动。

Don't know in other versions, but in 1.4.2 you can attach multiple events, so the behaviour when you do this 不知道在其他版本中,但在1.4.2中你可以附加多个事件,所以当你这样做时的行为

$(button).click( function() { return false; } 
$(button).click( function() { return true; } 

will be 'return false;return true;' 将为“返回false;返回true;”

$(button).unbind('click');
$(button).click( function() { return true; } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM