jquery - 无法拖动对象的克隆 (JQuery)

标签 jquery jquery-ui drag-and-drop clone

当我尝试拖动克隆对象时,它会拖动原始对象。我该如何解决这个问题?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='js/jquery-1.4.4.min.js'></script>
<script type='text/javascript' src='js/jquery-ui-1.8.6.custom.min.js'></script>
<style type='text/css'
    #calendar {width: 900px; margin: 0 auto;}
    .container {position: absolute;    top: 0pt; left: 0pt;}
    .block {background-color: rgb(153, 255, 102); position: absolute; z-index: 8; width: 131px;    height: 50px;border: 1px solid;}
</style>
<script type='text/javascript'>    
    $(function() {
        $( ".block" ).draggable();
        selector = $('.special').clone(true).show()
        .css({left:'', top:'', position:'', borderWidth:'1px', marginBottom: '2px'})
        .find('span').text('Cloned').end().appendTo('.container');
    });
</script>
</head>
<body>
<div id='calendar'>    
    <div class="container">                
        <div class="block special" style="left: 278px; top: 300px;">
            <span>Original</span>
        </div>        
    </div>
</div>
</body>
</html>

最佳答案

正如您所发现的,jQuery 中的.clone(true) 克隆了原始元素的事件处理程序。

要解决此问题,您可以尝试使用此答案中定义的 liveDraggable 函数:

jQuery Drag And Drop Using Live Events

关于jquery - 无法拖动对象的克隆 (JQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4474249/

相关文章:

css - 如何删除 jQueryUI 自动完成组合上的 BG 图像(选择)

javascript - HTML5 多个文件上传 : Set Filenames with JavaScript?

javascript - jQuery 拖放不起作用

javascript - Select2 4.0.3 无法使用 ajax 调用填充其他 select2 字段

javascript - 如何在 if 语句中仅追加一个项目一次?

javascript - 在鼠标悬停时以某种方式在 div 中显示图像

javascript - 禁用日期选择器会更新输入中的日期

jquery - 通过拖放交换元素 (jQuery)

jquery - $(window).scroll(function() 在 Firefox 上不起作用?

javascript - jQuery - 选择器和 $(this)