JQuery 对话框帮助
因此,我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将成功代码更改为:
这样,它将通过
dialog('open')
调用确保打开它Try changing the success code to this:
This way it will make sure its open with the
dialog('open')
call我认为这是因为一旦
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)
您应该只调用一次来创建对话框
要打开对话框,请调用
$("#history").dialog("open");
我建议在页面首次加载时创建对话框 < code>autoOpen: false 并根据需要打开它们
You should only call this once to create the dialog
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