由于某种原因,我无法就此问题发表评论:
jQuery Mobile 1.4 Nested Popups
我尝试过接受的答案,但没有成功。我的HTML是:
<div data-role="main" class="ui-content">
<button id="showpopup1">Show popup 1</button>
<div id="popup1" data-role="popup">
<h1>Popup 1</h1>
<button id="showpopup2">Show popup 2</button>
<a href="#" data-rel="back">Close</a>
</div>
<div id="popup2" data-role="popup">
<h1>Popup 2</h1>
<a href="#" data-rel="back">Close</a>
</div>
</div>
和代码(使用建议的解决方案):
$(document).on("mobileinit", function() {
var originalHandleLink = $.mobile.popup.handleLink;
$.mobile.popup.handleLink = function(link) {
var activePopup = $.mobile.popup.active,
path = $.mobile.path;
if (activePopup) {
var popup = $(path.hashToSelector(
path.parseUrl(link.attr("href")).hash)).first();
if (popup.length > 0 && popup.data("mobile-popup")) {
activePopup._close(true);
}
}
originalHandleLink.apply(this, arguments);
};
});
$('#showpopup1').click(function() {
$('#popup1').popup('open');
});
$('#showpopup2').click(function() {
$('#popup2').popup('open');
});
这就是这个小提琴: