【发布时间】:2014-06-30 06:59:30
【问题描述】:
如何使用 sortable.我可以获取拖动项目的 ID,但无法获取要删除的项目的 ID。这是我迄今为止尝试过的代码:
$(function () {
$('#sortable').sortable({
//to prevent items from moving around when draging
containment: "parent",
start: function (event, ui) {
// get the initial position(index) of item
var start_pos = ui.item.attr('id');
ui.item.data('start_pos', start_pos);
},
update: function (event, ui) {
var index = ui.item.index();//position of dropped
var start_pos = ui.item.attr('id');//position of dragged
alert(start_pos);
alert(index);
// Iterate over all <li> elements
$.each($('#sortable li'), function (idx, item) {
// $(item).html(html + ' - ' + (idx + 1));
});
},
axis: 'y'
});
例如,如果我将项目从位置 1 拖动到位置 5,我想提醒 1 和 5
【问题讨论】:
标签: jquery jquery-ui jquery-ui-sortable jquery-ui-droppable