jQuery Mobile - 資料佔位符 Selectmenu



描述

佔位符指定了描述預期值的一條簡短提示。在選項元素中新增屬性data-placeholder = "true"以指定一條小提示。

示例

以下示例展示了在 jQuery Mobile 中,select 選單中資料佔位符的使用。

<!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 data placeholder Example</h2>
      <div class = "ui-field-contain">
         <label for = "select-custom">Custom Select</label>
         
         <select id = "select-custom" data-native-menu = "false">
            <option value = "choose-one" data-placeholder = "true">Choose any one</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_data_placeholder.html檔案。

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

jquery_mobile_widgets.htm
廣告
© . All rights reserved.