我想创建一个div,可以在父div中拖动并丢弃?
答
你可以用户Jquery-UI Droppable组件。
示例代码:
<div id="draggable" class="ui-widget-content">
<p>Drag me to my target</p>
</div>
<div id="droppable" class="ui-widget-header">
<p>Drop here</p>
</div>
和:
$("#droppable").droppable({
drop: function(event, ui) {
$(this)
.addClass("ui-state-highlight")
.find("p")
.html("Dropped!");
}
});
编辑: 您需要添加jQuery和jQuery的UI库:
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
请注意,这个例子来自jQuery UI网站。
编辑: 见this fiddle example.
基本上你需要添加你的逻辑在下拉事件。这只是一个简单的例子,只是改变拖放区域的背景颜色。
请在您的问题中包含您的代码尝试。我们不是一个编码服务。 –
[请访问这里以获得更多关于如何提问的问题](https://stackoverflow.com/help/how-to-ask) –