周末的东西。我使用ajaxForm插件,它工作正常。但是使用after()创建的表单通常只会提交给url并发布ajax。提交后()表格不使用Ajax
$("a.update-time").live("click", function(event) {
event.preventDefault();
var row = $(this).attr("id").split('-');
$("#update-mini-form").remove();
$(this).after(
'<div id="update-mini-form"><form method="post" action="' + 'http://drupal.se/timetracker/timetracker/update_time/' + row[1] + '"> ' +
'<input type="textfield" name="title" value="">' +
'<input type="textfield" name="event_date" value="">' +
'<input type="textfield" name="hours" size="2" value="">' +
'<input type="submit" value="update">' +
'</form></div>'
);
});
$('#update-mini-form').live("submit", function(){
var row = $(this).closest('a').attr("id").split('-');
$(this).ajaxForm({
url: 'http://drupal.se/timetracker/timetracker/update_time/' + row[1],
target:$("div#row-" + row[1]),
type: "POST",
});
});
题外话:你为什么不只有一种形式,并四处移动它,而不是删除并重新创建它?那么你不需要现场注册提交事件。也是一个适当的委托事件的方式是使用on()而不是live。 –
你使用的是什么版本的jQuery?自从jQuery 1.7以来,'live()'就没有了。 – Vishal
@poelinca,我想到了第一个,但得到了编码器块。这是一个隆重的日子。我会在早上试一试。 –