HTML DOM Input Search value 属性
htmlweb developmentfront end technology更新于 2024/5/28 11:24:17
HTML DOM Input Search value 属性与 type="search" 的输入元素及其 value 属性相关联。它用于返回或设置输入搜索字段 value 属性的值。此属性用于指定搜索字段的默认值,也可用于将值更改为用户输入的值。
语法
以下是语法 −
设置 value 属性 −
searchObject.value = text;
此处,text 用于指定搜索字段的值。
示例
让我们看一个 Input Search value 属性的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>Input search Value property</h1>
<form>
FRUITS: <input type="search" id="SEARCH1" name="fruits">
</form>
<p>Get the above element value by clicking the below button</p>
<button onclick="getValue()">Get Value</button>
<p id="Sample"></p>
<script>
function getValue() {
var t = document.getElementById("SEARCH1").value;
document.getElementById("Sample").innerHTML = "The value for the input field is : "+t;
}
</script>
</body>
</html>
输出
这将产生以下输出 −

输入一些文本,然后点击"获取值"按钮 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

