jQuery Mobile - 選定的選項



說明

<select> jQuery mobile 元素用於定義選擇列表。在 <option> 標記中新增屬性selected = "selected" 以在預設情況下選擇特定選項。

示例

以下示例展示如何在 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 Selected Option Example</h2>
      <form>
         <div class = "ui-field-contain">
            <label for = "select">Select Menu</label>
            
            <select name = "select" id = "select">
               <option value = "1">Belgaum</option>
               <option value = "2" selected = "selected">Pune</option>
               <option value = "3">Chennai</option>
               <option value = "4">Bangalore</option>
               <option value = "5">Mumbai</option>
            </select>
            
         </div>
      </form>
   </body>
</html>

輸出

讓我們執行以下步驟,檢視以上程式碼如何工作 -

  • 將上述 HTML 程式碼另存為selectmenu_selected_option.html檔案,並將其儲存到伺服器根資料夾中。

  • 以 https:///selectmenu_selected_option.html 的形式開啟此 HTML 檔案,便會顯示以下輸出。

jquery_mobile_widgets.htm
廣告
© . All rights reserved.