jQuery Mobile - 表單選擇選單



說明

選擇選單將建立包含可選選擇的簡單選單。<select></select> 元件用於定義選擇列表,而 <option></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>
      <div data-role = "page">
         <div data-role = "header">
            <h2>Form Select Menus</h2>
         </div>
         
         <div data-role = "main" class = "ui-content">
            <form method = "post" action="jquery_mobile/demo.php">
               
               <fieldset class = "ui-field-contain">
                  <label for = "fname">Form Select Menu</label>
                  <select id = "select" name = "fname">
                     <option value = "Pune">Pune</option>
                     <option value = "Belgaum">Belgaum</option>
                     <option value = "Chennai">Chennai</option>
                     <option value = "Bangalore">Bangalore</option>
                  </select>
               </fieldset>
               
               <input type = "submit" value = "Submit" data-inline = "true">
            </form>
         </div>
         
      </div>
   </body>
</html>

輸出

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

  • 在伺服器根資料夾中將上述 html 程式碼儲存為 form_select_menus.html 檔案。

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

jquery_mobile_forms.htm
廣告
© . All rights reserved.