HTML DOM 输入搜索类型属性


HTML DOM 输入搜索类型属性与具有 type=”search”属性的 input 元素相关联。它将始终为 input 搜索元素返回搜索。

语法

以下是搜索类型属性的语法 -

searchObject.type

示例

我们来看看输入搜索类型属性的一个示例 -

在线演示

<!DOCTYPE html>
<html>
<body>
<h1>Search type property</h1>
<form>
FRUITS: <input type="search" id="SEARCH1" name="fruits">
</form>
<p>Get the above element type by clicking the below button</p>
<button onclick="getType()">Get Type</button>
<p id="Sample"></p>
<script>
   function getType() {
      var t = document.getElementById("SEARCH1").type;
      document.getElementById("Sample").innerHTML = "The type for the input field is : "+t;
   }
</script>
</body>
</html>

输出

这将产生以下输出 -

单击“获取类型”按钮 -

更新于: 19-2-2021

91 浏览

开启你的职业

完成课程认证

立即开始
广告
© . All rights reserved.