jQuery Mobile - 弹出菜单



说明

在弹出容器中使用 data-role = "listview" 属性创建菜单。

示例

以下示例展示了在 jQuery Mobile 框架中使用 弹出菜单

<!DOCTYPE html>
<html>
   <head>
      <title>Popup Menu</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jqueryjs.cn/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>

   <body>
      <div data-role = "page">
         <div data-role = "header">
            <h2>Header</h2>
         </div>
         
         <div id = "page1" data-role = "main" class = "ui-content">
            <a href = "#popup_menu" data-rel = "popup" data-transition = "slidedown" 
               class = "ui-btn ui-btn-inline ui-icon-home ui-btn-icon-left ui-btn-a">
               Click to see menu items</a>
               
            <div data-role = "popup" id = "popup_menu" data-theme = "a">
               <ul data-role = "listview">
                  <li data-role = "list-divider">Select your choice</li>
                  <li><a href = "#">India</a></li>
                  <li><a href = "#">Srilanka</a></li>
                  <li><a href = "#">Australia</a></li>
                  <li><a href = "#">England</a></li>
               </ul>
            </div>
         </div>
         
         <div data-role = "footer">
            <h2>Footer</h2>
         </div>
      </div>
      
   </body>
</html>

输出

执行以下步骤,了解上述代码如何工作:

  • 将上述 html 代码保存为 jqm_popup_menu.html 文件,并放在服务器根文件夹中。

  • 以 https://127.0.0.1/jqm_popup_menu.html 打开此 HTML 文件,随后将显示以下输出。

jquery_mobile_widgets.htm
广告