动态创建jQuery对话框&追加到DIV.对话框被创建,但不在DIV中

Dynamically creating jQuery Dialog box & append it to DIV . Dialog is created but not within the DIV

本文关键字:DIV 对话框 创建 jQuery 追加 动态      更新时间:2023-09-26
$('.image').draggable({
    revert:'invalid',
    helper:'clone',
});
$('#content').droppable({
    accept:'.image',
    drop:function(event , ui{
        $('<div>').appendTo('#content').dialog();               
    }
});

对话框被创建,但不是在CONTENTdiv中。它被创建在body下面!为什么不附加在CONTENT下面

我相信这篇博文可以比我更好地解释它http://blog.pengoworks.com/index.cfm/2007/10/26/jQuery-Understanding-the-chain

jQuery总是引用链中的第一个元素,除非你使用显式更改链的命令

如果有人对jquery网站上的上述引用有参考,请将其发布,因为我也想刷新我对这方面的知识。

更新:实际上,上述可能不是你的问题(因为它仍然有效),似乎对话框本身有一些问题,因为它实际上被添加在这里:http://forum.jquery.com/topic/dialog-will-move-its-div-tag-to-body

这些似乎已经解决,所以它确实取决于你的版本的jquery UI见这里:http://api.jqueryui.com/dialog/option-appendTo

$('.image').draggable({
    revert:'invalid',
    helper:'clone',
});
$('#content').droppable({
    accept:'.image',
    drop:function(event , ui{
        $('#content').dialog({ appendTo: "#content" });               
    }
});

dialog() -函数将其移出#contentdiv。创建一个小的div,其中只需将常规(非dlg)div插入到#content ->中即可。然后我在html(非javascript)中插入另一个div,并使对话框->从#content

移出。