Ajax jquery mobile:将事件处理程序添加到页面对话框关闭按钮

Ajax jquery mobile:将事件处理程序添加到页面对话框关闭按钮,ajax,jquery-mobile,dialog,Ajax,Jquery Mobile,Dialog,以对话框样式打开页面时,默认情况下会添加“关闭”按钮。是否有方法捕获对话框页面关闭按钮的单击事件。我喜欢在对话框页面关闭之前调用回调 <div data-role="page" id="page1"> <div data-role="header" data-position="fixed" data-tap-toggle="true" > <h1>Page 1</h1> </div> <

以对话框样式打开页面时,默认情况下会添加“关闭”按钮。是否有方法捕获对话框页面关闭按钮的单击事件。我喜欢在对话框页面关闭之前调用回调

<div data-role="page" id="page1">

    <div data-role="header" data-position="fixed" data-tap-toggle="true" >
        <h1>Page 1</h1>
    </div>

    <div role="main" class="ui-content">
        This is Page1.

        <a href="#" class="ui-btn ui-corner-all" onclick="showDialog();">Show Dialog</a>

    </div>

    <script>
        function showDialog() {
            $(":mobile-pagecontainer").pagecontainer("change", "#page2", { role: "dialog" } );

        }
   </script>

</div>


<div data-role="page" id="page2">

    <div data-role="header" data-position="fixed" data-tap-toggle="true" >
        <h1>Dialog</h1>
    </div>

    <div role="main" class="ui-content">

        This is Dialog
    </div>
</div>

第1页
这是第一页。
函数showDialog(){
$(“:mobile pagecontainer”).pagecontainer(“更改”、“第2页”{role:“对话框”});
}
对话
这是对话
可以使用pagecontainerhide事件。但它对ajax不起作用。如果对话框页面是在DOM中动态创建的,则不会为隐藏事件定义ui.prevPage


感谢您的帮助。

关闭按钮是一个锚定标记(
带有ui对话框类的DOM元素:

$(document).on("pagecreate", "#page1", function(){

    $(document).on("click", ".ui-dialog-contain .ui-header a", function(e){
        alert("close dialog: " + $(this).closest(".ui-dialog").prop("id"));       
    });

});

$(document).on("pagecreate", "#page1", function(){

    $(document).on("click", ".ui-dialog-contain .ui-header a", function(e){
        alert("close dialog: " + $(this).closest(".ui-dialog").prop("id"));       
    });

});