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