HTML DOM Input Reset type 属性
htmlweb developmentfront end technology更新于 2025/9/26 7:40:17
HTML DOM Input Reset type 属性与 type="reset"的输入元素关联。对于输入重置元素,它将始终返回 reset。
语法
以下是 Reset type 属性的语法 −
resetObject.type
示例
让我们来看一个重置类型属性的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>Input reset type Property</h1>
<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>
<p>Get the above input element type by clicking the below button</p>
<button type="button" onclick="resetType()">GET Type</button>
<p id="Sample"></p>
<script>
function resetType() {
var P=document.getElementById("RESET1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is: "+P ;
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击 GET 类型属性 −

在上面的例子中 −
我们创建了一个 <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 Type",当用户点击该按钮时,它将执行 resetType() 方法 −
<button type="button" onclick="resetType()">GET Type</button>
resetType() 方法使用 getElementById() 方法获取输入元素,并将其 type 属性值赋给变量 P。然后,该变量会使用其 innerHTML 属性显示在 id 为"Sample"的段落中。 −
function getType() {
var P = document.getElementById("RESET1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+P;
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

