2013-08-26 21 views
0

我想在拖放到div時獲取拖動項目的div ID。 我的問題是,當我把它放到第3層時,它也讀取第1層和第2層。 我想要的只是第3層,因爲它被徘徊。當使用jquery刪除一個對象時得到div ID

請考慮下面的代碼。

在此先感謝。

<div> 

<img class="item" src="img.jpg"/> 
</div> 
<div id="layer1" class="droppable" style="width:100px; height : 100px ;"> 
<div id="layer2" class="droppable" style="width:70px; height : 70px; "> 
    <div id="layer3" class="droppable" style="width:50px; height: 50px"> 
      Drop an image here </div> 
    </div> 
</div>  
<script> 
$(function(){ 
$(".droppable").droppable({ accept : 'item' , drop : Calldropp });  
function Calldropp(){ 
    <!-- what to do here --> 
    } 

}) 
</script> 

回答

0

嘗試使用event.stopPropagation

$(function(){ 
    $(".droppable").droppable({ accept : 'item' , drop : Calldropp });  
    function Calldropp (event){ 
     event.stopPropagation(); 
    } 
}); 

這應在最內部元件停止滴加傳播。

相關問題