删除“可拖动”对象时,Javascript 陷入无限循环。
我遇到这个特殊问题:当我将一个可拖动对象拖放到可放置对象上,然后删除此可拖动对象(可拖动对象是“文件和文件夹”,可放置对象是“垃圾箱”)时,在“放置事件”的回调中,javascript陷入无限循环。我的确切代码是:
$("#trash").droppable({
over : function () {$("#trash").addClass("over")},
out : function () {$("#trash").removeClass("over")},
drop : function (e, ui) {
$("#trash").removeClass("over");
var id=$($(ui.draggable).parent()).attr("id"), fl=false;
$($(ui.draggable).parent()).hide();
$(".ui-draggable-dragging").remove();
if (id[1]=='l') {
fl=true;
id=flid(id);
}else{
id=fid(id);
}
$.post("ajax/recycle_file.php", {fid : id, folder : fl}, function (data) {
var elid=$($(ui.draggable).parent()).attr("id");
$("#"+elid).draggable("destroy");
$("#"+elid).remove(); //Here is where the endless loop starts
});
}
});
我从 Google Chrome 的 javascript 控制台收到的消息是:
Uncaught TypeError: Cannot read property 'options' of undefined
I am having this particular problem: When I drop a draggable onto a droppable and then delete this draggable (The draggables are "files and folders" and the droppable is "Trash Bin"), inside the callback of the "drop event", javascript falls to endless loop. My exact code is:
$("#trash").droppable({
over : function () {$("#trash").addClass("over")},
out : function () {$("#trash").removeClass("over")},
drop : function (e, ui) {
$("#trash").removeClass("over");
var id=$($(ui.draggable).parent()).attr("id"), fl=false;
$($(ui.draggable).parent()).hide();
$(".ui-draggable-dragging").remove();
if (id[1]=='l') {
fl=true;
id=flid(id);
}else{
id=fid(id);
}
$.post("ajax/recycle_file.php", {fid : id, folder : fl}, function (data) {
var elid=$($(ui.draggable).parent()).attr("id");
$("#"+elid).draggable("destroy");
$("#"+elid).remove(); //Here is where the endless loop starts
});
}
});
The message I get from the javascript console of Google Chrome is:
Uncaught TypeError: Cannot read property 'options' of undefined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论