如何使用sortable来获取要删除拖动项目的项目的ID。我可以获取被拖动项目的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
答案 0 :(得分:0)
尝试以下代码: - )
$('.selector').droppable({ drop: Drop });
function Drop(event, ui) {
var draggableId = ui.draggable.attr("id");
var droppableId = $(this).attr("id");
}