jQuery Mobile - 所選項 Selectmenu



描述

在 <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 Empty Option Value Example</h2>
      <div class = "ui-field-contain">
         <label for = "select-custom">Custom Select</label>
         
         <select id = "select-custom" data-native-menu = "false">
            <option value = "mu">Mumbai</option>
            <option value = "pu">Pune</option>
            <option value = "be" selected = "selected">Belgaum</option>
            <option value = "ch">Chennai</option>
            <option value = "ban">Bangalore</option>
         </select>
         
      </div>
   </body>
</html>

輸出

讓我們執行以下步驟,瞭解以上程式碼如何執行 −

  • 將以上的 HTML 程式碼另存為selectmenu_custom_selected_option.html 檔案,並將其儲存至伺服器根資料夾。

  • 以 https:///selectmenu_custom_selected_option.html 的方式開啟此 HTML 檔案,即可顯示以下輸出。

jquery_mobile_widgets.htm
廣告
© . All rights reserved.