2008-11-12 142 views
0

目前我有一組div,由php動態生成,並且所有的ids都以'itembox'開頭,並附有計數。我在頁面上有一個可放置的垃圾箱區域,以便用戶可以通過fdragging和放入垃圾箱來刪除單個的itembox。jQuery可拖拽/可拖拽

我的問題是,當我拖動原件時,droppable似乎不會激活,而當我有helper時它會起作用(完全):'clone'set。然而,不幸的是,當拖動時,克隆函數會從itembox的第一次迭代中獲取其克隆,無論實際拖動哪個itembox。

所以我正在尋找一個解決方案,以使droppable接受原創或強制克隆功能從itembox實際拖動它的克隆。

回答

1

我想這個問題必須存在於你的droppable初始化器的accept選項中。剛剛嘗試以下操作:

$('#mydroppable').droppable(
{ 
    accept: function() { return true; }, 
    drop: function() { alert("Dropped!"); } 
}); 

現在,這將接受一切,所以你應該落實在接受功能,一些過濾,但沒有少這應該工作。

0

您也可以嘗試下面的解決方案。

<script type="text/javascript"> 
$(document).ready(function(){ 
    $('.srcfield').draggable({ 
     revert: true  
    }); 

    $('#trash').droppable({ 
     accept : ".srcfield", 
     over: function(){ 
      $(this).removeClass('out').addClass('over'); 
     },`enter code here` 
     out: function(){ 
      $(this).removeClass('over').addClass('out'); 
     }, 
     drop: function(ev, ui){ 
      //var answer = confirm('Delete this item?'); 
      var theTitle = $(ui.draggable).attr("title"); 
      $(this).html("<u>"+theTitle+"</u><br/> is deleted!"); 
     } 
    }); 
}); 
</script> 


<body> 
    <div id="trash" class="out"> 
      <span>Trash</span> 
    </div> 
    <div id="sourcefields"> 
      <div class="srcfield" title="First Name"><span>First Name</span></div> 
      <div class="srcfield" title="Last Name"><span>Last Name</span></div> 
      <div class="srcfield" title="Age"><span>Age</span></div> 
    </div> 
</body>