JQuery 对话框帮助

发布于 2024-11-05 06:17:53 字数 1077 浏览 1 评论 0原文

因此,我的 UI 上有一个调用此 Javascript 函数的按钮:

function OpenHistory(transactionId, spanThatWasClicked)
    {   
        $.ajax({
            type: "POST",
            url: "<%= Url.Action("ViewHistory", "Indications") %>",
            data : { transactionId : transactionId },
            success: function(data) {
                $("#history").html(data);
                $("#history").dialog({
                    modal: true,
                    resizable: false,
                    title: "Valuation History",
                    width: 850,
                    height: 500,
                    autoOpen: true,
                    buttons: { "Close": function () { $(this).dialog("close"); } }
                });
            }
        });
    }

它的设置在页面上看起来像这样:

我第一次点击它——进行 AJAX 调用,打开对话框,一切看起来都很完美。

关闭对话框

我第二次单击它 - 没有任何反应。它进行 AJAX 调用和所有操作,但屏幕上不会出现任何对话框。

刷新页面

仅在第一次点击时它就会恢复正常工作,就像上次一样。

这是一些奇怪的对话吗?

谢谢。

So I have a button on my UI that calls this Javascript function:

function OpenHistory(transactionId, spanThatWasClicked)
    {   
        $.ajax({
            type: "POST",
            url: "<%= Url.Action("ViewHistory", "Indications") %>",
            data : { transactionId : transactionId },
            success: function(data) {
                $("#history").html(data);
                $("#history").dialog({
                    modal: true,
                    resizable: false,
                    title: "Valuation History",
                    width: 850,
                    height: 500,
                    autoOpen: true,
                    buttons: { "Close": function () { $(this).dialog("close"); } }
                });
            }
        });
    }

The #history it's setting just looks like this on the page: <div id="history"></div>

First time I click it -- makes the AJAX call, opens the dialog, everything looks perfect.

Close the dialog

Second time I click it -- nothing happens. It makes the AJAX calls and everything, but no dialog appears on the screen.

Refresh the page

It goes back to working again on the FIRST click only, just like last time.

Is this some dialog weirdness?

Thanks.

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

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

发布评论

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

评论(3

煞人兵器 2024-11-12 06:17:53

尝试将成功代码更改为:

      success: function(data) {
            $("#history").html(data)
             .dialog({
                modal: true,
                resizable: false,
                title: "Valuation History",
                width: 850,
                height: 500,
                autoOpen: true,
                buttons: { "Close": function () { $(this).dialog("close"); } }
            }).dialog('open');
        }

这样,它将通过 dialog('open') 调用确保打开它

Try changing the success code to this:

      success: function(data) {
            $("#history").html(data)
             .dialog({
                modal: true,
                resizable: false,
                title: "Valuation History",
                width: 850,
                height: 500,
                autoOpen: true,
                buttons: { "Close": function () { $(this).dialog("close"); } }
            }).dialog('open');
        }

This way it will make sure its open with the dialog('open') call

|煩躁 2024-11-12 06:17:53

我认为这是因为一旦 autoOpen 在后续调用中没有触发,对话框就已经创建了。尝试在 ajax 调用中添加 $("#history").dialog("open") 并查看是否有帮助。
您可以添加一些优化以确保不会两次调用原始对话框创建代码(某种布尔变量)

I think it's because the dialog was already created once the autoOpen doesn't trigger on subsequent calls. Try adding $("#history").dialog("open") in the ajax call and see if that helps.
You could add some optimization to make sure you don't call the original dialog creation code twice (some kind of a boolean variable)

郁金香雨 2024-11-12 06:17:53

您应该只调用一次来创建对话框

           $("#history").dialog({
                modal: true,
                resizable: false,
                title: "Valuation History",
                width: 850,
                height: 500,
                autoOpen: true,
                buttons: { "Close": function () { $(this).dialog("close"); } }
            });

要打开对话框,请调用 $("#history").dialog("open");

我建议在页面首次加载时创建对话框 < code>autoOpen: false 并根据需要打开它们

You should only call this once to create the dialog

           $("#history").dialog({
                modal: true,
                resizable: false,
                title: "Valuation History",
                width: 850,
                height: 500,
                autoOpen: true,
                buttons: { "Close": function () { $(this).dialog("close"); } }
            });

To open the dialog call $("#history").dialog("open");

I recommend creating your dialogs when the page is first loaded with autoOpen: false and opening them as needed

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