2014-11-24 61 views
0

對不起,我的英語不好。我有以下建設。Block onmousedown for child element

<div onmousedown="drag_drop(ev)" class="abc"> 
    <img src="test.jpg"></img> 
    <div class="xyz"></div> 
</div> 

當我拖動圖片時,「onmousedown」事件被觸發。我怎樣才能防止這一點?當「test.jpg」被拖動時,我需要移動「abc」塊。

回答

0

你必須檢查事件的目標是正確的,例如:當你點擊圖片

drag_drop = function (evt) { 
    if (evt.target.classList.contains('abc')) { 
    //you have clicked the outer div 
    } 
} 
+0

這樣的結構塊整個塊的轉移。只能在塊後面傳輸它。如何在img焦點時讓div動起來? – JeiKei 2014-11-25 08:28:35

相關問題