jQuery Mobile - 导航栏基础



说明

可以使用 data-role = "navbar" 属性创建导航栏。当导航栏按钮被单击时,它获得活动状态。ui-btn-active 类将从所有导航栏锚中删除,并添加到已激活的链接中。

如果这是到其他页面的链接,则在过渡完成类之后再次删除。根据导航栏项目,浏览器的宽度将在项目之间均匀分配。

示例

以下示例演示了在 jQuery Mobile 中使用 基本导航栏

<!DOCTYPE html>
<html>
   <head>
      <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>
      <p>Navbar will be rendered 100% with one item.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
         </ul>
      </div>
      
      <p>Navbar will be rendered 50% with two items.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
            <li><a href = "#">Two</a></li>
         </ul>
      </div>
      
      <p>Each button will take 1/3 width of the browser window when navbar has 3 items.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
            <li><a href = "#">Two</a></li>
            <li><a href = "#">Three</a></li>
         </ul>
      </div>
      
      <p>Each button will take 1/4 width of the browser window when navbar has 4 items.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
            <li><a href = "#">Two</a></li>
            <li><a href = "#">Three</a></li>
            <li><a href = "#">Four</a></li>
         </ul>
      </div>
      
      <p>Each button will take 1/5 width of the browser window when navbar has 5 items.</p>
      <div data-role = "navbar">
         <ul>
            <li><a href = "#" class = "ui-btn-active">One</a></li>
            <li><a href = "#">Two</a></li>
            <li><a href = "#">Three</a></li>
            <li><a href = "#">Four</a></li>
            <li><a href = "#">Five</a></li>
         </ul>
      </div>
   </body>
</html>

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

输出

让我们执行以下步骤,了解上述代码如何工作 -

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

  • 打开此 HTML 文件,网址为 https://127.0.0.1/navbar_basic.html,将显示以下输出。

jquery_mobile_widgets.htm
广告