我在搞乱一些代码,我有一个列表,我已经应用了可拖动函数,另一个 div 有一个 drop 函数。
我想要实现的是当列表元素被删除时,它会从父列表中删除并添加到另一个列表中。
这是我正在玩的代码:
<div id='dAvail'>
<ul>
<li><div class='abox'>1</div></li>
<li><div class='abox'>2</div></li>
</ul>
</div>
<div id='somewhereToDrop'>
</div>
<div id='newListHere'>
<ul>
</ul>
</div>
JS:
$(document).ready(function(){
//add the droppable function to the divs in main list
$('#dAvail ul).each(function(){
$('li>div).draggable();
});
$('#somewhereToDrop').droppable({
tolerance:'touch',
drop:function(event,ui){
//this is where I am having problems.
//if I do ui.draggable I get an object representing the object I dragged but not 100% how to remove said object from the orginal list to then append to the new one.
//this is what i tried.
var t = ui.draggable[0]; //represents the div that i dropped.
$(t).parent().parent().remove($(t).parent());
//that is as far as I have gotten as this returns an error
});
如果有人能指出如何从列表中删除该对象,那就太好了。我什至试图看看我是否可以做 $(t).parent().eq() 但这不起作用,我的想法是获取列表索引然后像这样删除它。
谢谢