0
我有一些代碼,如下所示:爲什麼jQuery .live()不能在我的.ajaxForm()調用中使用?
jQuery("[name='myform']").live('submit', function() {
$(this).ajaxForm({
target: '#someform',
beforeSerialize: function(form, options) {
alert("BeforeSerialize happening.");
jQuery('form[name=myform] input[type=submit]').attr('disabled', 'disabled').attr("value", "<%= t('labels.please_wait') %>");
return true;
}
else {
return false;
}
}
return false;
},
success: function() {
jQuery('#form_quotes_highlights_part').fadeIn('slow');
},
complete: function() {
jQuery("#wizard").expose().close();
}
});
});
活()結合似乎工作得很好,但是給ajaxForm是不工作的。如果我這樣做:
$(document).ready(function() {
/* ajax form stuff here */
});
它似乎工作得很好。唯一的問題是,當響應從服務器返回時,JavaScript處理程序沒有正確地將自己附加到DOM,因此使用live()。無論哪種方式,beforeSerialize從來不會以我當前正在處理我的live()處理程序的方式調用,所以不是使用ajaxForm,而是使用整頁提交。
什麼是最好的清理方法?
有一些代碼丟失。你有一個'else',但沒有'if'。 – Guffa 2010-10-29 19:21:52