【发布时间】:2016-08-28 09:31:30
【问题描述】:
我使用 jQuery 可排序。我希望能够获得移动项目的 ID 和它替换的项目的 ID。到目前为止,我能够获取移动元素的 ID,但不能获取它替换的元素。
我的代码是:
$(function () {
$("#sortable").sortable({
stop: function (event, ui) {
var moved = ui.item,
replaced = ui.item.prev();
// if replaced.length === 0 then the item has been pushed to the top of the list
// in this case we need the .next() sibling
if (replaced.length == 0) {
replaced = ui.item.next();
}
alert("moved ID:" + moved.attr("id"), "replaced ID:" + replaced.attr("id"));
}
});
});
如何取回被替换元素和被移动元素的 ID?
【问题讨论】:
标签: javascript jquery jquery-ui jquery-ui-sortable