我正在使用此代码:
$(document).ready(function () {
$("#step1_next").validate({
submitHandler: function(form) {
$.post('step2.php', $("#step1_next").serialize(), function(data) {
$('#step2_div').html(data);
$("#step2_form").on("submit", function() {
$.post('../model/step2.php', $("#step2_form").serialize(), function(data) {
$('#step2_controller').html(data);
});
return false;
});
});
}
});
});
基本上,我想要做的是,当呈现step2.php时,另一个ajax函数被附加到step2_form(在step2.php中)。
此代码无法正常工作,因为尚未加载“step2_form”。我该怎么办?
答案 0 :(得分:0)
使用.on()
使用事件委派$(document).ready(function () {
$("#step1_next").validate({
submitHandler: function(form) {
$.post('step2.php', $("#step1_next").serialize(), function(data) {
$('#step2_div').html(data);
$(document).on("submit", "#step2_form", function() {
$.post('../model/step2.php', $("#step2_form").serialize(), function(data) {
$('#step2_controller').html(data);
});
return false;
});
});
}
});
});