2013-01-07 42 views
0

我有2个jQuery函数,一个允许排序和一个允许从列表中删除div。一切工作正常,直到我删除其中一个列表项。然后拖动停止工作,直到我刷新页面。可排序不工作后刷新排序Div

我也有麻烦,删除功能不会立即删除点击要删除的div,如果点击多个,只有最近将被删除。这是为什么刷新下面的删除功能的div。

任何帮助将不胜感激!

JQuery的可排序

$(document).ready(function(){ 
      function slideout(){ 
     setTimeout(function(){ 
     $("#response").slideUp("slow", function() { 
      }); 

    }, 2000);} 

     $("#response").hide(); 
     $(function() { 
     $("#list ul").sortable({ opacity: 0.8, cursor: 'move', update: function() { 

       var order = $(this).sortable("serialize") + '&update=update'; 
       $.post("updateReadingList.php", order, function(theResponse){ 
        $("#response").html(theResponse); 
        $("#response").slideDown('slow'); 
        slideout(); 
       });                
      }         
      }); 
     }); 

    }); 

JQuery的删除功能

$(document).ready(function(){ $(function() { 
     $('#reading').on('click', 'a.deletefromrl', function(){ 
      $(this).closest('li').fadeOut('slow'); 
      var order = $('#list ul').sortable("serialize") + '&update=update' + '&id=' + $(this).attr('data-storyid'); 
      $.post("deletefromReadingList.php", order, function(theResponse){ 
        $("#response").html(theResponse); 
       }); 
       var auto_refresh = setInterval(
        function() 
        { 
         $('ul').load('reloadReadingList.php'); 
        }, 0); 
     }) 
    }) 
    }) 
+1

当您在删除功能中重新加载列表时,您应该考虑重新绑定排序列表。这应该使它工作。 – Maffelu

+0

我该怎么做?很抱歉,我对JQuery很陌生。谢谢您的帮助! – nggonzalez

回答

1

一个解决办法是把粘合作用在它自己的功能和调用它在页面加载,然后每次你刷新你的列表:

编辑: 我不知道最后一个错在哪里,但这似乎s为我工作:

$(document).ready(function(){ 
    function slideout(){ 
     setTimeout(function(){ 
     $("#response").slideUp("slow", function() { 
      }); 

    }, 2000);} 

    function bindSortable() 
    { 
     $("#list ul").sortable(
     { 
      opacity: 0.8, 
      cursor: 'move', 
      update: function() { 

       var order = $(this).sortable("serialize") + '&update=update'; 
       $.post("updateReadingList.php", order, function(theResponse){ 
        $("#response").html(theResponse); 
        $("#response").slideDown('slow'); 
        slideout(); 
       });                
      }         
     }); 
    } 

    bindSortable(); 

    $('#reading').on('click', 'a.deletefromrl', function(){ 
     $(this).closest('li').fadeOut('slow'); 
     var order = $('#list ul').sortable("serialize") + '&update=update' + '&id=' + $(this).attr('data-storyid'); 
     $.post("deletefromReadingList.php", order, function(theResponse){ 
       $("#response").html(theResponse); 
      }); 
      var auto_refresh = setInterval(
       function() 
       { 
        $('ul').load('reloadReadingList.php', function() 
        { 
         bindSortable(); 
        }); 
       }, 0); 
    }) 
}); 
+0

这不起作用,它由于某种原因禁用了拖放和其他功能。 – nggonzalez

+0

我编辑了解决方案,新的适用于我。你有没有试过在[FireBug](http://www.firebug.com/)中进行调试? – Maffelu

+0

我正在尝试,但我真的不知道我在做什么或发生了什么。这里是我正在工作的网站:www.cgrtutoring.com/index7.php有我的代码,www.cgrtutoring.com/index9.php有上面的代码。 但是当我调试index7.php它只是说登录刷爆GET重装脚本,然后它显示2号线在查询界面是的,但我不知道这意味着什么 – nggonzalez