问题描述
||
我有以下几点:
$(\'#xxxxx\').submit(function() {
....
});
它包含在一个名为w jQuery getScript的脚本中。如何确保此绑定仅被应用一次?或者,还是事先清除?
谢谢解决方法
$(\'#xxxxx\').unbind(\'submit\').submit(function() {
....
});
,您可以使用\'unbind \':
$(\'#xxxxx\').unbind(\'click\').
bind(\'click\',function() {
....
})
,附加处理程序时,将一个类添加到表单。再次附加时,只需检查该类是否已添加到表单中。
var $xxxx = $(\'#xxxx\')
if (!$xxxx.hasClass(\'handleradded\')) {
$xxxx.submit(function(){
....
}).addClass(\'handleradded\');
}
别人给出的解决方案是好的。我只是想给你一个选择。 :)