gpt4 book ai didi

javascript - 如何使用javascript将多个div拖放到一个div中

转载 作者:行者123 更新时间:2023-11-30 00:15:01 24 4
gpt4 key购买 nike

我在前面提到的一个项目上遇到了问题,现在的问题是我想将一个 div 拖放到另一个 div 上。如果我拖动一个 div,那么它应该被添加到之前拖放的 div 下面。我怎样才能做到这一点?我当前的代码没有附加下一个 div,它覆盖了第一个。我尝试了很多解决方案,但最终都弊大于利。谁能帮帮我,谢谢。

<html>
<head>
<title>CRM</title>
<link rel="stylesheet" href="style/style.css" type="text/css">
<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 type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>


<script>
$(document).ready(function(){

$(".dragable").draggable({
cancel:"a.ui-icon",
revert:true,
helper:"clone",
cursor:"move",
revertDuration:0
});

$('.droppable').droppable({
accept: ".dragable",
activeClass: "ui-state-highlight",
drop: function( event, ui ) {
// clone item to retain in original "list"
var $item = ui.draggable.clone();

$(this).addClass('has-drop').html($item);

}
});
});
</script>

</head>

<body>
<div class="main-container">
<div class="wrapper">
<div class="tb-head">

<div class="target">
<span class="target-span">Target</span>
</div>

<div class="user1">
<span class="user1-span">User1</span>
</div>

<div class="user2">
<span class="user2-span">User2</span>
</div>

<div class="user3">
<span class="user3-span">User3</span>
</div>

<div class="user4">
<span class="user4-span">User4</span>
</div>

<div class="clear"></div>
</div>

<div class="tb-body">

<div class="inner-target">

<div class="dragable">
<span class="targetinn-span">Target Lead</span>
</div>

<div class="dragable">
<span class="targetinn-span">Assign1 Lead</span>
</div>

<div class="dragable">
<span class="targetinn-span">Assign2 Lead</span>
</div>

<div class="dragable">
<span class="targetinn-span">Assign3 Lead</span>
</div>

</div>

<div class="inner-user1">
<div class="droppable">
<span class="user1inn-span"></span>
</div>
</div>

<div class="inner-user2">
<div class="droppable">
<span class="user2inn-span"></span>
</div>
</div>

<div class="inner-user3">
<div class="droppable">
<span class="user3inn-span"></span>
</div>
</div>

<div class="inner-user4">
<div class="droppable">
<span class="user4inn-span"></span>
</div>
</div>

<div class="clear"></div>
</div>
</div>

</body>
</html>

最佳答案

只改这行代码

$(this).addClass('has-drop').html($item);

对此

$(this).addClass('has-drop').append($item);

通过调用 .html(),您仅用最后放置的元素替换了原始 html。

关于javascript - 如何使用javascript将多个div拖放到一个div中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35084016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com