HTML DOM Input Reset form 属性
htmlweb developmentfront end technology更新于 2025/10/17 1:16:17
HTML DOM Input Reset form 属性用于返回包含指定重置按钮的表单引用。如果重置按钮位于表单之外,则返回 NULL。此属性为只读属性。
语法
以下是 Input Reset form 属性的语法。
resetObject.form
示例
让我们来看一个 Input Reset form 属性的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>Input reset form Property</h1>
<form id="FORM_1" style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id="Age"> <br><br>
<input type="reset" id="RESET1">
</form>
<p>Get the form id by clicking on the below button</p>
<button type="button" onclick="formId()">GET FORM</button>
<p id="Sample"></p>
<script>
function formId() {
var P=document.getElementById("RESET1").form.id;
document.getElementById("Sample").innerHTML = "The id of the form containing the reset button is: "+P ;
}
</script>
</body>
</html>
这将产生以下输出 −

点击"获取表单"按钮 −

在上面的例子中 −
我们创建了一个 <input> 元素,其 type=”reset”,id=”RESET1”。点击此按钮将重置表单数据。此按钮位于一个包含两个文本字段的表单内,并且该表单还应用了内联样式。
<form style="border:solid 2px green;padding:2px"> UserName: <input type="text" id="USR"> <br> Location: <input type="text" id="Age"> <br><br> <input type="reset" id="RESET1"> </form>
然后,我们创建了一个按钮 GET FORM,当用户点击该按钮时,它会执行 formId() 方法。
<button type="button" onclick="formId()">GET FORM</button>
formId() 方法使用 getElementById() 方法获取类型为 reset 的输入字段,并获取包含重置按钮的表单对象的 id 属性。然后,它将该值赋给变量 P,并使用其 innerHTML 属性在 id 为"Sample"的段落中显示该值。 −
function formId() {
var P=document.getElementById("RESET1").form.id;
document.getElementById("Sample").innerHTML = "The id of the form containing the reset button is: "+P ;
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

