繁体   English   中英

当可拖动元素创建克隆副本时,jQuery克隆不起作用

[英]jQuery clone is not working when draggable elements create cloned copy

我是jQuery Draggable功能的新手,我需要通过克隆drag元素并将其放置到指定位置来创建拖放功能。 这是我的代码

 $(function () {
             $('#Draggable' + Localvar + '').draggable({
                 snap: true,
                 helper: 'clone',

             }
                 );
             $('#Droppable').droppable({
                 accept: $('#Draggable' + Localvar + ''),
                 drop: function (event, ui) {
                 }
             });
         });

代码创建了一个克隆,它可以拖动但不能删除。

您应该参加一门基础的JS课程,以了解为什么需要引用字符串,什么是选择器以及如何使用它们。

这是代码的基本设置,请注意"包装选择器。

 $(function () { $("#Drag").draggable({ snap: true, helper: 'clone' }); $("#Droppable").droppable({ accept: $("#Drag"), drop: function (event, ui) { alert('dropped'); } }); }); 
 .ui-widget-content { width: 60px; height: 60px; padding: 0.5em; } .ui-widget-header { width: 60px; height: 60px; margin: 1em; } 
 <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <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> <div id="Drag" class="ui-widget-content">Drag me</div> <div id="Droppable" class="ui-widget-header">Drop here</div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM