gpt4 book ai didi

javascript - 如何在jquery可排序中获取移动ID和替换ID?

转载 作者:行者123 更新时间:2023-11-28 18:25:47 24 4
gpt4 key购买 nike

我正在使用 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?

jsFiddle

最佳答案

实际上它是有效的,你只是用错误的参数调用警报;将其替换为 console.log 或连接字符串,如下所示:

alert("moved ID:" + moved.attr("id") + "replaced ID:" + replaced.attr("id"));

(我用 + 替换了 ,)

关于javascript - 如何在jquery可排序中获取移动ID和替换ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39189854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com