JavaScript 应用后如何更改列表的顺序jQuery.sortable
.
例如:
<ul id="mylist">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
var x_sortable_list = $("mylist").sortable();
然后,假设这有效:
x_sortable_list.changeOrder([
{item:1, newOrder:2 },
{item:2, newOrder:1 },
{item:3, newOrder:3 }
]);
就像其他人提到的那样,这与 sortable() 功能无关。相反,您需要检索列表中的项目,移动它们的位置,然后清除并按新顺序重新插入列表项目:
// Get your list items
var items = $('#mylist').find('li');
// The new index order for each item
var order = [4, 2, 0, 1, 3];
// Map the existing items to their new positions
var orderedItems = $.map(order, function(value) {
return items.get(value);
});
// Clear the old list items and insert the newly ordered ones
$('#mylist').empty().html(orderedItems);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)