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. :)
精彩评论