在jQuery.html()更新时,其他函数将停止工作


on jQuery .html() update, other functions stop working

我的网站上有一些可排序的"页面"。它们还自动更新到数据库。

在我的li列表排序后,会调用一个php页面来重新排序"页面",然后我调用.html(data)来更改页面上显示的页面的顺序。

然而,完成此操作后,javascript中的自动更新功能停止工作。

在进行排序和调用.html(data)之前,有一个#form1起作用。调用后,会删除上一个#form1 get并将其重新添加到页面中。这是它停止工作的时候。

有人知道原因吗?

我的更新脚本

$("#reportNav").sortable({
    stop : function(event, ui){
        var postData = $(this).sortable('serialize');
        var url = "saveOrder.php";
        $.ajax({
            type: "POST",
            url: url,
            data: postData,
            success: function(data) {  $('#reportContainer').html(data); },
            error: function(data) { $changesSaved.text("Could not re-order pages."); }
        });
    }
});

什么停止工作/停止被调用

var timeoutId;
$('#form1').on('input propertychange change', function() {
   clearTimeout(timeoutId);
    timeoutId = setTimeout(function() {
    // Runs 1 second (1000 ms) after the last change  
    $("#form1").submit();
   }, 1000);
 });

可能是重写绑定了处理程序的元素的情况,在这种情况下,您需要事件委派:

$('#reportContainer').on('input propertychange change', '#form1', function() {