HTML DOM Input 搜尋 placeholder 屬性
HTML DOM Input 搜尋 placeholder 屬性用於設定或返回輸入搜尋欄位的 placeholder 屬性值。placeholder 屬性用於透過在使用者輸入任何內容之前在輸入欄位內顯示文字,向網頁使用者提供有關輸入元素的提示。與 value 屬性不同,placeholder 文字預設呈灰色,不會提交到表單中。
語法
以下是其語法 −
設定 placeholder 屬性 −
searchObject.placeholder = text
此處,text 表示指定使用者搜尋欄位提示資訊的佔位符文字。
示例
讓我們看一個 input search placeholder 屬性的示例 −
<!DOCTYPE html> <html> <body> <h1>earch placeholder property</h1> <form> FRUITS: <input type="search" id="SEARCH1" name="fruits"> </form> <p>Change the placeholder text of the above field by clicking the below button</p> <button onclick="changeHolder()">CHANGE</button> <script> function changeHolder() { document.getElementById("SEARCH1").placeholder = "Search for the fruits here.."; } </script> </body> </html>
輸出
將生成以下輸出 −
點選 CHANGE 按鈕 −
廣告