【问题标题】:$("#dialog").parent().appendTo($("form:first"));$("#dialog").parent().appendTo($("form:first"));
【发布时间】:2011-05-08 15:00:52
【问题描述】:

我在我的页面上打开了几个 jQuery 对话框,我正在使用:

$("#dialog2").parent().appendTo($("form:first")); //This was working, no problem.

我注意到当我再次将它应用到 dialog3 时,它已经停止了该行在对话框 2 上的工作。如何将它用于不同的对话框?

$("#dialog2").dialog({
    bgiframe: false,
    autoOpen: false,
    height: 410,
    width: 800,
    modal: true,
    draggable: true,
    resizable: true
});

$("#dialog2").parent().appendTo($("form:first")); //doesn't work now

$("#dialog3").dialog({
    bgiframe: false,
    autoOpen: false,
    height: 410,
    width: 600,
    modal: true,
    draggable: true,
    resizable: true
});

$("#dialog3").parent().appendTo($("form:first"));

HTML:

<div id="dialog3" title="Attachments">
    <p id="P1">
        <asp:Button ID="btnAttach" runat="server" Text="Attach files" class="float-left ui-button"/></p>
    <fieldset>

    </fieldset>
</div>


<div id="dialog2" title="Notes">
    <asp:Image ID="Image1" runat="server" ImageUrl="~/images/icons/user_comment.png" />
    <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Larger" Text="Notes"></asp:Label>
    <br />
    &nbsp;
    <div style="overflow: auto; height: 310px; width: 780px;">
        <fieldset>
            <br />
            <asp:TextBox ID="txtNote" runat="server" CssClass="notetext" Width="740px" Rows="6"
                TextMode="MultiLine" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" />
            <br />
            &nbsp;
            <div style="width: 743px">
                <asp:Button ID="btnNoteSave" runat="server" Text="Save" class="float-right ui-button" />
            </div>
        </fieldset>
    </div>

【问题讨论】:

  • 我无法重现这个 - 我的精简版工作正常。 (我基本上删除了 ASP.NET 控件声明并使用了原版 html。)当您说“它已停止该行在对话框 2 上的工作”时,确切的症状是什么?您在 Firebug/Fiddler 中遇到错误吗?
  • 发生的事情是:两个 jquery 对话框都出现了。如果我只是把 $("#dialog2").parent().appendTo($("form:first"));然后 dialog2 上的按钮将单击并运行它背后的方法 - 太棒了。如果我添加 $("#dialog3").parent().appendTo($("form:first"));然后 dialog3 上的按钮将单击并运行它后面的方法,但是当我调用 dialog2 时,它的按钮将不会运行它后面的方法。我试过把: $("#dialog3").parent().appendTo($("form:second")); ...作为猜测,但这也不起作用!

标签: asp.net jquery jquery-ui-dialog


【解决方案1】:

更好的-

$('#dialog2').dialog({
      open:function(){{
         $(this).parent().appendTo($("form:first"));
      }}
});

$('#dialog3').dialog({
      open:function(){{
         $(this).parent().appendTo($("form:first"));
     }}
});

【讨论】:

    【解决方案2】:

    好的,我现在似乎两个按钮都在工作,即浏览两个按钮后面的代码。我将“appendTo”调用放在打开对话框的函数中......

            $('#edit-notes').click(function() {
                $('#dialog2').dialog('open');
                $("#dialog2").parent().appendTo($("form:first"))
                return false;
            });
    
            $('#attachments').click(function() {
                $('#dialog3').dialog('open');
                $("#dialog3").parent().appendTo($("form:first"))
                return false;
            });
    

    【讨论】:

      猜你喜欢
      • 2011-10-18
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 2015-07-02
      • 2016-10-16
      相关资源
      最近更新 更多