1

当我拖放到某个 div 时,我想获得多个拖动的 id。$(ui.draggable).attr('id');仅获得第一个 ID。

  Drag  <ul id="demo" > 
         <li id="1" ></li>
         <li id="2" ></li>
        <li id="3" ></li>
        </ul>

         <div class="drop"> drop here!! </div>

查询

$(".drop").droppable({ 
                drop: function(event, ui) {

  var m_id = $(ui.draggable).attr('id');// only gets 1st id


      // i need to get multiple dragged id 

            1,2,3..     

            }       
            });

请帮帮我!!谢谢

4

2 回答 2

3
var m_id = [];
$.each($(ui.draggable), function(i,e) {
   m_id.push(e.id);
});

//gives array with all ID's, could be joined with join()
//for comma seperated list
于 2012-05-19T15:22:05.400 回答
0
$("li").draggable({ revert: true });

$(".drop").droppable({
drop: function(event, ui) {
    var id = ui.draggable.attr("id");
    alert(id);
}
});  
于 2014-11-24T06:11:04.747 回答