如何在 jquery sortable 中获取移动 ID 和替换 ID?
How to get moved ID and replaced ID in jquery sortable?
我正在使用 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?
实际上它有效,你只是用错误的参数调用警报;将其替换为 console.log
或像这样连接字符串:
alert("moved ID:" + moved.attr("id") + "replaced ID:" + replaced.attr("id"));
(我用+
替换了,
)
我正在使用 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?
实际上它有效,你只是用错误的参数调用警报;将其替换为 console.log
或像这样连接字符串:
alert("moved ID:" + moved.attr("id") + "replaced ID:" + replaced.attr("id"));
(我用+
替换了,
)