专注前端素材!
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="https://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script> $(document).on("pagebeforeshow","#pagetwo",function(){ alert("触发 pagebeforeshow 事件 - 页面二即将显示"); }); $(document).on("pageshow","#pagetwo",function(){ alert("触发 pageshow 事件 - 现在显示页面二"); }); $(document).on("pagebeforehide","#pagetwo",function(){ alert("触发 pagebeforehide 事件 - 页面二即将隐藏"); }); $(document).on("pagehide","#pagetwo",function(){ alert("触发 pagehide 事件 - 现在隐藏页面二"); }); </script> </head> <body> <div data-role="page" id="pageone"> <div data-role="header"> <h1>页眉文本</h1> </div> <div data-role="main" class="ui-content"> <p>页面一</p> <a href="#pagetwo">转到页面二</a> </div> <div data-role="footer"> <h1>页脚文本</h1> </div> </div> <div data-role="page" id="pagetwo"> <div data-role="header"> <h1>页眉文本</h1> </div> <div data-role="main" class="ui-content"> <p>页面二</p> <a href="#pageone">转到页面一</a> </div> <div data-role="footer"> <h1>页脚文本</h1> </div> </div> </body> </html>
运行结果