<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追加另一个项目之后使列表可排序,我该怎么做?
答案 0 :(得分:2)
在ajax 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
}
});