ui.draggable的jquery ui错误(“destroy”)

时间:2012-04-05 08:16:15

标签: javascript jquery jquery-ui jquery-ui-draggable jquery-ui-droppable

当我将它放在容器上时,我想删除<div>的拖动属性。但是对于我的代码,我收到了错误"Property 'draggable' of object #<Object> is not a function"

$( "#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

3 个答案:

答案 0 :(得分:0)

我的猜测是'ui'是一个简单的旧javascript对象而不是jQuery对象 尝试(修改):
$(ui.draggable).draggable("destroy");

答案 1 :(得分:0)

调用methods of draggable widget的语法是:

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

您应该将方法名称作为string传递给draggable()方法。

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

您应该在其上调用draggable()并传递方法名称:

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

答案 2 :(得分:0)

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

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