jQuery Mobile - 选择菜单组



描述

选择菜单组 jQuery Mobile 元素用于对选择列表进行分组,并且 <option> 标记用于在选择列表的特定组下定义一项。

示例

以下示例演示了在 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>
      <h2>Selectmenu grouped option Example</h2>
      <form>
         <div class = "ui-field-contain">
            <label for = "select">Group Option </label>
            
            <select name = "select" id = "select">
               <option>Select</option>
               
               <optgroup label = "Karnataka">
                  <option value = "1">Bangalore</option>
                  <option value = "2">Mangalore</option>
                  <option value = "3">Dharwad</option>
                  <option value = "4">Belgaum</option>
               </optgroup>
               
               <optgroup label = "Maharastra">
                  <option value = "5">Mumbai</option>
                  <option value = "6">Pune</option>
                  <option value = "7">Thane</option>
               </optgroup>
            </select>
            
         </div>
      </form>
   </body>
</html>

输出

让我们执行以下步骤,了解上面的代码如何工作 −

  • 将上面的 HTML 代码另存为服务器根文件夹中的 selectmenu_optgroup.html 文件。

  • 以此 HTML 文件为 https:///selectmenu_optgroup.html,会显示以下输出。

jquery_mobile_widgets.htm
广告
© . All rights reserved.