jquery
  • jquery-ui
  • drag-and-drop
  • clone
  • 2010-12-17 202 views 2 likes 
    2

    當我嘗試拖動克隆的對象時,它拖動了原始對象。我怎樣才能解決這個問題?無法拖動對象克隆(JQuery)

    <!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> 
    

    回答

    1

    正如您發現的,在jQuery中的.clone(true)克隆了原始元素的事件處理程序。

    要解決這個問題,你可以嘗試使用這個答案定義的liveDraggable功能:

    jQuery Drag And Drop Using Live Events

    相關問題