無值空的選項 選擇器



說明

在自定義選擇器選單中,任何沒有值的 <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 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></option>
            <option value = "mu">Mumbai</option>
            <option value = "pu">Pune</option>
            <option value = "be">Belgaum</option>
            <option value = "ch">Chennai</option>
            <option value = "ban">Bangalore</option>
         </select>
         
      </div>
   </body>
</html>

輸出

讓我們執行以下步驟,看看上面的程式碼如何工作 −

  • 將以上 HTML 程式碼另存為selectmenu_empty_option_value.html檔案儲存在伺服器根目錄中。

  • 開啟此 HTML 檔案,網址為 https:///selectmenu_empty_option_value.html,將顯示以下輸出。

jquery_mobile_widgets.htm
廣告
© . All rights reserved.