jQuery Mobile - 在多个页面上弹出
描述
通过使用 data-demo-html 属性将弹出窗口指定为 body 元素的子元素,您可以在多个页面上使用相同的弹出窗口。
示例
以下示例演示了在 jQuery Mobile Framework 中跨多个页面弹出的使用。
<!DOCTYPE html> <head> <title>Popup on Multiple Pages</title> <meta name = "viewport" content = "width = device-width, initial-scale = 1"> <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script> <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script id = "popup_script"> $(function() { $( "#popup_page" ).enhanceWithin().popup(); }); </script> </head> <body> <div id = "popup_page" data-theme = "a"> <ul data-role = "listview"> <li>Global Menu</li> <li><a href = "#first_page">First Page</a></li> <li><a href = "#second_page">Second Page</a></li> <li><a href = "#third_page">Third Page</a></li> </ul> </div> <div data-role = "page" id = "first_page" class = "jqm-demos"> <div role = "main" class = "ui-content jqm-content"> <h2>Example of same popup on multiple pages</h2> <div data-demo-html = "#popup_page,#second_page,#third_page" data-demo-js = "#popup_script"> <a href = "#popup_page" data-rel = "popup" class = "ui-btn ui-btn-inline ui-corner-all">Click to see menu items</a> </div> </div> </div> <div id = "second_page" data-role = "page"> <div data-role = "header"> <a href = "#popup_page" data-rel = "popup">Menu</a> <h2>Second Page</h2> </div> <div role = "main" class = "ui-content"> <p>This is second page.</p> </div> </div> <div id = "third_page" data-role = "page"> <div data-role = "header"> <a href = "#popup_page" data-rel = "popup">Menu</a> <h2>Third Page</h2> </div> <div role = "main" class = "ui-content"> <p>This is third page.</p> </div> </div> </body> </html>
输出
让我们执行以下步骤,看看上面的代码是如何工作的 −
将上述 html 代码保存为服务器根文件夹中的 jqm_popup_across_multiple_pages.html 文件。
将此 HTML 文件打开为 http://localhost/jqm_popup_across_multiple_pages.html,将显示以下输出。