簡體   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