附加到
后,jQuery 对话框不再起作用

发布于 2024-09-14 22:36:21 字数 1652 浏览 3 评论 0原文

我有一个表单和该表单中的一个 div,我将其用于 jQuery 对话框的内容。我的目标是弹出对话框,用户在文本框和文本区域中输入一些信息,然后提交表单并使该数据可供我后面的代码使用,然后能够重新打开对话框(页面提交后保持状态),输入新数据,然后根据需要重新提交表单。

如果我运行:

$('div#mydialog').appendTo($('form#foo'));

然后:

 $('div#mydialog').dialog('open');

会显示一个仅包含按钮的对话框,并且在其后面显示 div,用户无法访问。 (简而言之,它看起来像 UI 小部件的集群交互)

为什么将 div#mydialog 附加到表单(这是它开始的地方)然后调用 .dialog('open') 会导致这种行为,以及在将其附加到 form#foo 以将用户数据发送到服务器后如何使其正常打开?

预先感谢

编辑:由于某种原因,对话框在最初打开后似乎没有被附加。即它被打开/编辑/关闭多次,用户单击“提交”,div 被附加到表单中,然后当我再次尝试对话框('打开')时,Firebug 显示它保持在原来的位置表单 - jQuery 似乎不再尝试移动它,而只是更改其内联样式。有谁知道为什么会这样?

编辑2:我不知道我的html/脚本对你有多大帮助,它基本上就是你想象的那样:

    <form id="foo"><! -- some form stuff -->
  <div id="stufftoputindialog" style="display:none;">
    <!-- text boxes/textareas to put in dialog -->
  </div>
</form>

点击

    $('#stufftoputindialog').dialog({
            height: 550,
            width: 400,
            modal: true,
            buttons: {
                "OK": function () { $(this).dialog("close"); },
                "Cancel": function () { $(this).dialog("close"); }
            },
            autoOpen: false
        }

编辑按钮:

   $('#stufftoputindialog').dialog('open');

提交表单:

$('#stufftoputindialog').appendTo('form#foo');

然后再次单击编辑按钮,

$('#stufftoputindialog').dialog('open');

会导致 UI 崩溃(根据 Firebug,#stufftoputindialog 没有像第一次那样移动到 之前的表单之外)

I have a form and a div within that form that I am using for the contents of a jQuery dialog. My goal is to have the dialog pop up, the user enters some information in the text boxes and textareas there, then submit the form and have that data available to my code behind, but then be able to re-open the dialog (the page stays up after submit), enter new data, and resubmit the form if they wish.

If I run:

$('div#mydialog').appendTo($('form#foo'));

and then:

 $('div#mydialog').dialog('open');

a dialog shows up with only the buttons, and behind it the div is being shown, inaccessible to the user. (in short, it looks like a cluster-intercourse of UI widgets)

Why is it that appending div#mydialog to the form (which is where it was to begin with) and then calling .dialog('open') results in such behavior, and how can I get it to open normally after having appended it to form#foo to send the user's data to the server?

Thanks in advance

EDIT: it appears that for some reason the dialog is not being appended to after it is initially opened. i.e. it gets opened/edited/closed some number of times, user clicks "submit", div is appended to form, then when I try to dialog('open') again, Firebug shows that it is staying put right where it is in the form - jQuery appears not to try to move it again, instead just changing its inline styles. Does anyone know why this is so?

EDIT 2: I don't know how much of my html/script will help you, it's basically just what you would imagine it is:

    <form id="foo"><! -- some form stuff -->
  <div id="stufftoputindialog" style="display:none;">
    <!-- text boxes/textareas to put in dialog -->
  </div>
</form>

and

    $('#stufftoputindialog').dialog({
            height: 550,
            width: 400,
            modal: true,
            buttons: {
                "OK": function () { $(this).dialog("close"); },
                "Cancel": function () { $(this).dialog("close"); }
            },
            autoOpen: false
        }

on click of edit button:

   $('#stufftoputindialog').dialog('open');

on submit of form:

$('#stufftoputindialog').appendTo('form#foo');

then on click of edit button again,

$('#stufftoputindialog').dialog('open');

causes a UI trainwreck (and according to Firebug, #stufftoputindialog hasn't moved outside of the form to right before </body> like it did the first time)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

允世 2024-09-21 22:36:21

它位于一个您也需要移动的容器中,请执行以下操作:

$('div#mydialog').parent().appendTo('form#foo');

包装器用于标题栏之类的东西...查看您的源代码,当您调用 .dialog() 时,它会将其包装在另一个容器中

,您需要转到 .parent() 然后移动那个元素:)

It's in a container you need to move as well, do this instead:

$('div#mydialog').parent().appendTo('form#foo');

The wrapper is for things like the titlebar...look at your source, when you call .dialog() it's wrapping it inside another <div>, you need to go to that .parent() then move that element :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文