我已经阅读了SO上的许多拖放线程,并且我没有找到一个告诉我如何在拖动的元素被删除时获取被拖动元素的子元素id。
例如,如果你有
<div id='drag'>
<img id="something"/>//how do i get this id when #drag is dropped?
</div>
<div id='drop'>
</div>
和js
$('#drag').draggable({
containment: '#content',
scrollSensitivity: 60,
revert: 'invalid',
cursor: 'move'
});
$('#drop').droppable({
accept: '#albumImgs li',
activeClass: 'dropContainerOpen',
drop: function(event, ui) {
var fileName = $(ui.draggable.attr('alt'));
console.log(fileName);
}
});
答案 0 :(得分:1)
ui.draggable是您只需要对所需子项进行查询所需的拖动元素:
$('#drop').droppable({
accept: '#albumImgs li',
activeClass: 'dropContainerOpen',
drop: function(event, ui) {
var fileName = $(ui.draggable.attr('alt'));
console.log(ui.draggable.find('#something'))
console.log(fileName);
}
});