我有 2 个可放置的 div,当在其中任何一个上拖放时,我正在尝试获取该放置元素的 id。它总是返回 DOM 中第一个放置元素的 id。
$('#albumImgs li').draggable({
containment: '#content',
scrollSensitivity: 60,
revert: 'invalid',
cursor: 'move'
});
$('.dropContainerClosed').droppable({
accept: '#albumImgs li',
activeClass: 'dropContainerOpen',
drop: function(event, ui) {
var file = $(ui.draggable.find('img'));
var fileName = file.attr('alt');
var albumName = $('div.dropContainerClosed').attr('id');
console.log("fileName = "+fileName);
console.log("albumName = "+albumName);//always returns the first div.dropContainerClosed id in the DOM
if(albumName != undefined) {
$.post('addImage.php', {filen: fileName, albumn: albumName},
function(data) {
//do something here
}, 'json');
} else {
$.post('firstImage.php', {filen: fileName, albumn: albumName},
function(data) {
//do something here
}, 'json');
}
}
});