开发者

jQuery Submit Function - How not to have it binded if already binded

I have the following:

$('#xxxxx').submit(function() {
....
});

This is contained within a script that gets called w jQuery getScript... How can I make sure this bi开发者_如何学Cnd only gets applied once? And or, clear out beforehand?

Thanks


$('#xxxxx').unbind('submit').submit(function() {
....
});


you can use 'unbind' :

$('#xxxxx').unbind('click').
    bind('click', function() {
         ....
    })


Add a class to the form when attaching the handler. When attaching again, just check if the class is already added to the form.

var $xxxx = $('#xxxx')
if (!$xxxx.hasClass('handleradded')) {
  $xxxx.submit(function(){
      ....
  }).addClass('handleradded');
}

Solutions given by others are good ones. I just wanted to give you an alternative. :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜