Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery droppable对象执行destroy(),但抛出错误_Javascript_Jquery_Jquery Ui_Draggable_Destroy - Fatal编程技术网

Javascript jQuery droppable对象执行destroy(),但抛出错误

Javascript jQuery droppable对象执行destroy(),但抛出错误,javascript,jquery,jquery-ui,draggable,destroy,Javascript,Jquery,Jquery Ui,Draggable,Destroy,当我运行这个 $('#tgsBox1').droppable({ accept: "#tgsSquirrel", drop: function(e, ui) { ui.draggable.animate({ left: $(this).position().left + 25, top: $(this).position().top + 131 }).destroy(); } }); 可拖动

当我运行这个

$('#tgsBox1').droppable({
    accept: "#tgsSquirrel",
    drop: function(e, ui) {
        ui.draggable.animate({
            left: $(this).position().left + 25,
            top: $(this).position().top + 131
        }).destroy();
    }
});
可拖动元素实际上已被销毁(不再可拖动),但它给出了一个错误:

TypeError: ui.draggable.animate(...).destroy is not a function
ui.draggable.animate({

看起来类似于旧线程:,但是假设的解决方案(更新jQuery ui)没有解决这个问题。

在jQuery ui可拖动小部件中调用方法的语法是:

$( ".selector" ).draggable( "method" );
用于:
$(.selector”).draggable(“destroy”)

尝试按如下方式调用该方法:

$('#tgsBox1').droppable({
  accept: "#tgsSquirrel",
  drop: function(e, ui) {
    ui.draggable.animate({
        left: $(this).position().left + 25,
        top: $(this).position().top + 131
    }).draggable("destroy");
  }
});
它不再可拖动的原因可能是由于错误导致脚本执行停止

您可能还希望在动画完成后销毁可拖动文件:

$('#tgsBox1').droppable({
  accept: "#tgsSquirrel",
  drop: function(e, ui) {
    ui.draggable.animate({
        left: $(this).position().left + 25,
        top: $(this).position().top + 131
    },function(){
       ui.draggable.draggable("destroy");
    });
  }
});
伟大的非常感谢(我想投票支持你的答案,但我的声誉还太低)。我不明白的是:为什么我需要为可拖动对象的可拖动对象调用“destroy”方法?换句话说:
ui.draggable.draggable
中的两个draggable对象之间有什么区别?@Robbit有帮助吗。。?不能直接调用小部件函数,如
.destroy()
,必须将方法名称作为字符串传递给
draggable()
工厂函数。工厂将比较字符串并在其中调用相应的方法。facory中方法的实际名称可能是其他名称。。。