2016-02-25 38 views
0
$(".target").droppable({ 
       connectWith: ".connected", 
       drop: function (event, ui) { 
        var targetId = event.target.id;//--> id of the target (where elements will be dropped into) 
        var orderId;//--> id of the dragged element (NOT the targetId) 

        if ($(this).hasClass("source connected")) { 
         orderId = sourceElementSo; 
        } 
        else { 
         orderId = $(ui.draggable).attr("id"); 
        }; 

我試過ui.item和ui.draggable,但沒有成功如何在目標排序後收到拖動項目的類別?

PS:新手:)

+0

$(本).hasClass(「源連接「) –

+0

Thx @VladuIonut,但仍然無法正常工作! –

+0

你可以提供更多的細節或代碼的小提琴嗎? –

回答

0

$(function() { 
 
    $("#draggable").draggable(); 
 
    $("#droppable").droppable({ 
 
    connectWith: ".connected", 
 
     drop: function(event, ui) { 
 
     var targetId = event.target.id;//--> id of the target (where elements will be dropped into) 
 
        var orderId;//--> id of the dragged element (NOT the targetId) 
 

 
        if (ui.draggable.hasClass("connected")) { 
 
         \t console.log("ok"); 
 
         orderId = sourceElementSo; 
 
        } 
 
        else { 
 
         orderId = $(ui.draggable).attr("id"); 
 
        }; 
 
     } 
 
    }); 
 
    });
#draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; } 
 
    #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
    
 
<div id="draggable" class="ui-widget-content connected"> 
 
    <p>Drag me to my target</p> 
 
</div> 
 
    
 
<div id="droppable" class="ui-widget-header"> 
 
    <p>Drop here</p> 
 
</div>

相關問題