Rio*_*Rio 1 jquery jquery-ui droppable jquery-plugins draggable
我想知道为什么
$('#title').replaceWith('ha');
Run Code Online (Sandbox Code Playgroud)
将在外面工作
drop: function(event, ui) {}
Run Code Online (Sandbox Code Playgroud)
jquery的droppable脚本中的区域,但它不能在里面工作.具体来说,如果我这样做
$(".droppable").droppable({
drop: function(event, ui) {
$('#title').replaceWith('ha');
}
Run Code Online (Sandbox Code Playgroud)
我得到了Runtime Error (line 1102) data(...).options is null or not an object.此外,如果我$('#title').append('ha');在drop:中插入一个,它可以工作.但是,如果我把$('#title').replaceWith('ha');其他地方放在外面
$(".droppable").droppable({ /* */ });
Run Code Online (Sandbox Code Playgroud)
有用?
我发布这个作为答案,但实际上更多的是对Jon Erickson的答案的评论(我没有声誉点评论).18个月后,这仍然是IE中的一个错误,我只想通过建议setTimeout()来详细说明"如何在drop函数之外运行某些东西"部分
我通过传递一个匿名函数来解决问题,该函数将元素移除到setTimeout().根据您的快照或还原设置,您可能还需要考虑隐藏可拖动设置.
$(".droppable").droppable({
drop: function(event, ui) {
// do something interesting here...
// now get rid of the draggable
$(ui.draggable).hide();
setTimeout(function(){$(ui.draggable).remove();}, 1);
}
});
Run Code Online (Sandbox Code Playgroud)