HTML DOM Input Reset type 属性
HTML DOM Input Reset type 属性与具有 type=”reset”属性的 input 元素相关联。它总是会为 input reset 元素返回 reset。
语法
以下是 reset type 属性的语法 −
resetObject.type
示例
让我们看一个 reset 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>输出
这将产生以下输出 −

单击获取类型属性 −

在上面的示例中 −
我们创建了一个具有 type=”reset”,id=”RESET1”属性的 <input> 元素。单击此按钮将重置表单数据。此按钮位于一个包含两个文本字段且应用了内联样式的表单中 −
<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() 方法获取输入元素,并将它的类型属性值指定给变量 P。然后使用其 innerHTML 特性在 ID 为 “Sample” 的段落中显示此变量 −
function getType() {
var P = document.getElementById("RESET1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+P;
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP