当我将多个项目拖放到特定的 div 时,它只需要第一个元素。后来当我签入 console.log($(ui.draggable)) 长度为 1。
({selector:"", context:#1=({}), 0:#1#, length:1}) when i dragged 3 elements
请帮助我哪里出错了??
http://jsfiddle.net/akkiys/Hkfh2/4/
HTML 如下所示:
<ul id="drag" >
<li id="1">one</li>
<li id="2">two</li>
<li id="3">three</li>
<li id="4">four</li>
<li id="5">five</li>
</ul>
和 JavaScript:
var selectedClass = 'ui-state-highlight',
clickDelay = 600,
// click time (milliseconds)
lastClick, diffClick; // timestamps
$("#drag li")
// Script to deferentiate a click from a mousedown for drag event
.bind('mousedown mouseup', function(e) {
if (e.type == "mousedown") {
lastClick = e.timeStamp; // get mousedown time
} else {
diffClick = e.timeStamp - lastClick;
if (diffClick < clickDelay) {
// add selected class to group draggable objects
$(this).toggleClass(selectedClass);
}
}
}).draggable({
scroll: false,
revertDuration: 10,
// grouped items animate separately, so leave this number low
start: function(e, ui) {
ui.helper.addClass(selectedClass);
},
stop: function(e, ui) {
// reset group positions
$('.' + selectedClass).css({
top: 0,
left: 0
});
},
drag: function(e, ui) {
// set selected group position to main dragged object
// this works because the position is relative to the starting position
$('.' + selectedClass).css({
top: ui.position.top,
left: ui.position.left
});
}
});
$(".drop").droppable({
drop: function(event, ui) {
var droppableId = $(this).find('div.inner').attr("id");
//var id = ui.draggable.attr("id"); // i need to retrive multiple id
console.log($(ui.draggable))
var m_id = [];
$.each($(ui.draggable), function(i, e) {
m_id.push(e.id);
alert(m_id);
});
console.log(m_id);
}
});