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.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>
   </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.