Javascript 如何在jquery排序表中获取移动的ID和替换的ID?
我正在使用jquerysortable。我希望能够获取移动项目的ID和替换项目的ID。到目前为止,我能够获取移动元素的ID,但无法获取它所替换的元素的ID 我的代码是:Javascript 如何在jquery排序表中获取移动的ID和替换的ID?,javascript,jquery,jquery-ui,jquery-ui-sortable,Javascript,Jquery,Jquery Ui,Jquery Ui Sortable,我正在使用jquerysortable。我希望能够获取移动项目的ID和替换项目的ID。到目前为止,我能够获取移动元素的ID,但无法获取它所替换的元素的ID 我的代码是: $(function () { $("#sortable").sortable({ stop: function (event, ui) { var moved = ui.item, replaced = ui.item.prev();
$(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
实际上它是有效的,您只是用错误的参数调用alert;将其替换为
console.log
,或按如下方式连接字符串:
alert("moved ID:" + moved.attr("id") + "replaced ID:" + replaced.attr("id"));
(我用
+
替换了,
)实际上它是有效的,你只是用错误的参数调用alert;将其替换为console.log
,或按如下方式连接字符串:
alert("moved ID:" + moved.attr("id") + "replaced ID:" + replaced.attr("id"));
(我将,
替换为+
)