我在 jQuery Mobile 中有以下内容:
<script type="text/javascript">
$("#locate_results").live("pageinit", function(event) {
$("#venues li a").click(function(e) {
e.preventDefault();
// Update location
$(".ui-dialog").each(function() { $(this).dialog("close"); });
});
});
</script>
<div data-role="page">
<div data-role="header">My Form</div>
<div data-role="content">
... other content ...
<a href="#locator" data-rel="dialog">Choose a Location</a>
</div>
</div>
<div data-role="dialog" id="locator">
<div data-role="header">Search for a Location</div>
<div data-role="content">
<form action="/locate" method="post" data-rel="dialog">
<input type="text" name="query" />
<input type="submit" value="Search" />
</form>
</div>
</div>
/locate 的输出如下:
<div id="locate_results" data-role="dialog">
<div data-role="header">Search Results</div>
<div data-role="content">
<ul id="venues" data-role="listview">
<li><a href="#">Venue 1 Name</a></li>
... more results ...
</ul>
</div>
</div>
本质上,
- 用户点击“添加位置”链接。
- 在对话框中加载位置搜索表单
- 在第二个对话框中加载搜索结果
- 用户点击第二个对话框中的搜索结果。
第 5 步应该是关闭两个对话框,将用户返回到原始页面内容。但是,只有最上面的对话框 (#locate_results) 关闭。我也尝试了以下并得到了相同的结果:
$("#locate_results").dialog("close");
$("#locator").dialog("close");
和
$(".ui-dialog").dialog("close");
我已经尝试按照这些答案进行操作,但没有成功:
在 jQuery Mobile 中关闭所有打开的对话框的正确方法是什么?
jsFiddle 演示问题:
最佳答案
这似乎是一个错误。
这是 jQuery Mobile 的关闭方法的一个片段:
// Close method goes back in history
close: function() {
window.history.back();
}
发生的事情是某些浏览器在连续多次调用 window.history.back()
时遇到问题,因此调用 $(".ui-dialog").dialog("close")
只在历史中返回一次。但是,调用 window.history.go(-2)
似乎有效。
关于javascript - 以编程方式一次关闭多个 jQuery Mobile 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8672830/