【发布时间】:2023-03-25 06:10:02
【问题描述】:
周末的东西。我正在使用 ajaxForm 插件,它工作正常。但是使用 after() 创建的表单只能正常提交到 url 并发布 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",
});
});
【问题讨论】:
-
离题:你为什么不只有一个表单并移动它而不是删除并重新创建它?那么您将不需要使用 live 注册提交事件。委派事件的正确方法也是使用 on() not live。
-
你使用什么版本的jQuery?
live()自 jQuery 1.7 起已停售。 -
@poelinca,我首先想到了这一点,但被编码人员阻止了。这是一个漫长的一天。早上我会试一试。
-
这是在 Drupal 7 中,所以最高版本是 1.4.4。令人沮丧,但我现在无能为力。