2

我想在删除容器上的<div>时删除它的拖动属性。但是我得到了一个错误"Property 'draggable' of object #<Object> is not a function",我的代码如下。ui.draggable(“destroy”)的jquery ui错误

$("#fighter1").draggable(); //fighter1 is the id of draggable object 
$("#fighter2").draggable(); 
$("#fighter3").draggable(); 
$("#fighter4").draggable(); 
$("#fighter5").draggable(); 
$("#fighter6").draggable(); 
$("#dest").droppable({  //dest is the id of droppable object 
    drop: function(event, ui) { 
     ui.draggable("destroy"); //I get error here. 
    } 
}); 

我使用jQuery UI的版本1.8.12

+1

不相关的问题,但你可能要考虑当你有这么多的时候使用一个类作为可拖动的。例如:'$(“.draggable”).draggable();' – mekwall 2012-04-05 08:22:42

回答

0

我的猜测是, 'UI' 是一个简单的JavaScript老对象,而不是一个jQuery对象。
尝试(修订本):
$(ui.draggable).draggable("destroy");

+0

但是当我尝试获取对象的id时,它给了我null。 – northlondoner 2012-04-05 10:34:39

+0

啊,我的jquery-ui看起来很生锈,根据jquery-ui的演示: “$(this)表示可拖动的可拖动的元素,ui.draggable表示可拖动的元素。”参见修订版。 – 2012-04-05 14:30:38

0

的语法调用methods of draggable widget是:

$(".selector").draggable("method"); 

你应该通过方法的名称为stringdraggable()方法。

在drop事件回调中,ui.draggable只是对与可拖动元素对应的jQuery对象(语法的$(".selector")部分)的引用。

你应该实际调用它draggable(),并通过该方法名称:

ui.draggable.draggable("destroy"); 
----^-------  ------^------ 
selector    method name 
     --------^-------- 
    this guy executes the method 
0

我使用setTimeout函数解决了这个问题:

setTimeout(function(a){a.draggable("destroy");},100,ui.draggable);