HTML DOM Input Search name 属性

htmlweb developmentfront end technology更新于 2025/9/26 9:48:17

HTML DOM Input Search name 属性用于设置或返回重置按钮的 name 属性。name 属性有助于在表单数据提交到服务器后对其进行识别。JavaScript 也可以使用 name 属性来引用表单元素,以便稍后进行操作。

语法

以下是语法 −

设置 name 属性 −

searchObject.name = name

此处,name 用于指定 Search 字段的名称。

示例

让我们来看一个 Search name 属性的示例 −

<!DOCTYPE html>
<html>
<body>
<h1>Input search name Property</h1>
<form>
FRUITS: <input type="search" id="SEARCH1" name="fruits" maxlength="5">
</form>
<p>Change the name of the above search field by clicking the below button</p>
<button type="button" onclick="changeName()">CHANGE NAME</button>
<p id="Sample"></p>
<script>
   function changeName() {
      document.getElementById("SEARCH1").name ="SEARCH_2 ;
      document.getElementById("Sample").innerHTML = "Search field name is now SEARCH_2";
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击"更改名称"按钮 −


相关文章


有用资源