jQuery Mobile - 文字輸入佔位符



說明

佔位符指定一個簡短提示來描述預期值。在輸入元素中新增 屬性 placeholder = " " 以編寫佔位符。

示例

以下示例演示了在 jQuery Mobile 中使用 placeholder 輸入。

<!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>
      <form>
         <h2>Placeholder Input Type Example</h2>
         <label for = "src">Text Placeholder Input</label>
         <input type = "text" id = "src" placeholder = "Enter Something">

         <label for = "src1">Clear the Text Placeholder Field</label>
         <input type = "text" data-clear-btn = "true" id = "src1" placeholder = "Enter Something">

         <label for = "src2">Search Placeholder Input</label>
         <input type = "search" id = "src2" placeholder = "Search">

         <label for = "src3"> Textarea Placeholder Field</label>
         <textarea type = "textarea" id = "src3" placeholder = "Enter your message"></textarea>
      </form>
   </body>
</html>

輸出

讓我們執行以下步驟,瞭解上述程式碼如何工作:

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

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

jquery_mobile_widgets.htm
廣告
© . All rights reserved.