HTML DOM Input Search placeholder 属性

htmlweb developmentfront end technology更新于 2024/5/28 13:32:17

HTML DOM Input Search placeholder 属性用于设置或返回输入搜索字段的占位符属性值。占位符属性用于在用户输入任何内容之前,在输入字段内显示一段文本,向网页用户提示输入元素。占位符文本默认为灰色,并且与 value 属性不同,不会提交到表单。

语法

以下是语法 −

设置占位符属性 −

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>

输出

这将产生以下输出 −

点击"更改"按钮 −


相关文章


有用资源