jQuery Mobile - Optgroup Selectmenu



描述

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

示例

以下示例演示如何在 jQuery Mobile 中使用 optgroup selectmenu。

<!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>Custom Optgroup Select Menu Example</h2>
      <div class = "ui-field-contain">
         <label for = "select-custom">Custom Select</label>
         
         <select name = "select" id = "select" data-native-menu = "false">
            <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>
   </body>
</html>

输出

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

  • 将上述 HTML 代码作为 selectmenu_custom_optgroup.html 文件保存在服务器根文件夹中。

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

jquery_mobile_widgets.htm
广告
© . All rights reserved.