2012-08-10 36 views
0
<script> 
    $(function() { 
     $("#sortable").sortable(); 
     $("#sortable").disableSelection(); 
    }); 
    </script> 


<div class="demo"> 

<ul id="sortable"> 
    <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 1</li> 
    <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 2</li> 
    <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 3</li> 
    <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 4</li> 
    <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 5</li> 
    <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 6</li> 
    <li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 7</li> 
</ul> 

</div><!-- End demo --> 

我想列表排序後,通過ajax追加到另一個項目,我怎麼能做到這一點?如何讓由javascript創建的列表項排序?

+0

裏面的AJAX'成功:函數(){'你需要調用'$ ( '#sortable')。可排序()' – Ohgodwhy 2012-08-10 13:41:55

回答

2

在阿賈克斯success: function() {...}內追加新的列表項目後,您可以嘗試:

$("#sortable").sortable('destroy').sortable().disableSelection(); 

例如:

$.ajax({ 
    url: '', 
    type: '', 
    success: function() { 
    // all codes to append new list items 
    // then add following line 

    $("#sortable").sortable('destroy').sortable().disableSelection(); 

    // do something else if need 
    } 
});