开发者

Javascript disable button event completely

Hi I would like to know if its possible to do something similar to the example shown below.

// Script A
$('.submitButton').click(function() {
   if (not valid) {
       $(this).attr("disabled", "disabled");
   }
});

// Script B
$('.submitButton').click(function() {
    // Do something else here
});

I would like to know whether you can actually stop the click event in Script B if not valid in Script A. The reason for the two events being separate is due to the fact that Script A will be used as a sort of a plu开发者_如何转开发gin module which will be inserted at the header of the page.


Yes, you can call $(this).stopPropagation(); and then check for event.isPropagationStopped() in Script B.

read more @ http://api.jquery.com/event.stopPropagation/


use unbind. It will not fire the event again unless you bind it again


Would this work for you?

$(".submitButton").click(function(event){
    event.preventDefault();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜