2017-05-27 42 views
0

我的DIV結構有些像這樣,.droppable函數div

<div class="fromDiv"> 
.......From here I want to drag.......... 
</div> 
<div class="parantDiv"> 
    <div class="childFirst"> 
      ..Here Want to drop...... 
    </div> 
    <div class="childSecond"> 
      ..OrHere Want to drop...... 
    </div> 
</div> 

我想從fromDiv事業部... 拖東西,想丟棄在childFirst股利或childSecond Div ... 。

請幫我...........

+0

發表您的jQuery代碼,請 –

回答

1

您可以使用HTML5拖放,請檢查瀏覽器的支持

簡單的例子

<!DOCTYPE HTML> 
 
<html> 
 
<head> 
 
<style> 
 
.fromDiv,.childFirst, .childSecond { 
 
    width: 350px; 
 
    height: 70px; 
 
    padding: 10px; 
 
    border: 1px solid #aaaaaa; 
 
} 
 
</style> 
 
<script> 
 
function allowDrop(ev) { 
 
    ev.preventDefault(); 
 
} 
 

 
function drag(ev) { 
 
    ev.dataTransfer.setData("text", ev.target.innerHTML); 
 
} 
 

 
function drop(ev) { 
 
    ev.preventDefault(); 
 
    ev.target.innerHTML = ev.dataTransfer.getData("text"); 
 
} 
 
</script> 
 
</head> 
 
<body> 
 

 
<div class="fromDiv" draggable="true" 
 
ondragstart="drag(event)"> 
 
.......From here I want to drag.......... 
 
</div> 
 
<div class="parantDiv"> 
 
    <div class="childFirst" ondrop="drop(event)" ondragover="allowDrop(event)"> 
 
      ..Here Want to drop...... 
 
    </div> 
 
    <div class="childSecond" ondrop="drop(event)" ondragover="allowDrop(event)"> 
 
      ..OrHere Want to drop...... 
 
    </div> 
 
</div> 
 

 
</body> 
 
</html>

+0

不錯,但如果我們想拖回源拖動的數據,那麼這個邏輯是行不通的。 –

+0

@ManavSharma - 這取決於你的需求,如果你想拖回來,你可以在div.childFirst和div.childSecond中添加拖動事件。 –

+0

啊!對不起,傢伙......我的代碼工作正常....我只是錯過了一個類名... 謝謝 –