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 按钮 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP