HTML DOM Input Reset 对象
htmlweb developmentfront end technology更新于 2025/9/25 1:48:17
HTML DOM Input Reset 对象与类型为"reset"的 <input> 元素相关联。我们可以分别使用 createElement() 和 getElementById() 方法创建和访问类型为 reset 的输入元素。
属性
以下是 Input Reset 对象的属性 −
| 属性 | 描述 |
|---|---|
| autofocus | 设置或返回重置按钮在页面加载时是否自动获得焦点。 |
| defaultValue | 设置或返回重置按钮的默认值。 |
| disabled | 设置或返回重置按钮是否已禁用,或不是。 |
| form | 返回包含重置按钮的表单的引用。 |
| name | 设置或返回重置按钮的 name 属性值。 |
| type | 返回重置按钮的表单元素类型。 |
| value | 设置或返回滑块控件的 value 属性值。 |
示例
让我们看一个 Input Reset 对象的示例 −
<!DOCTYPE html>
<html>
<head>
<script>
function resetCreate() {
var Res = document.createElement("INPUT");
Res.setAttribute("type", "reset");
document.body.appendChild(Res);
}
</script>
</head>
<body>
<h1>Input Reset object</h1>
<p>Create an input field with type reset by clicking the below button</p>
<button onclick="resetCreate()">CREATE</button>
<br><br>
</body>
</html>
输出
这将产生以下输出 −

点击"创建"按钮 −

在上面的例子中 −
我们创建了一个 CREATE 按钮,当用户点击该按钮时,它将执行 resetCreate() 方法 −
<button onclick="resetCreate()>CREATE</button>
resetCreate() 方法使用文档对象的 createElement() 方法,通过传递 “INPUT” 作为参数来创建 <input> 元素。新创建的输入元素被赋值给变量 Res,并使用 setAttribute() 方法创建一个类型为 reset 的属性。
记住,setAttribute() 会创建该属性,如果该属性之前不存在,则会赋值。最后,在文档主体上使用 appendChild() 方法,我们将类型为 reset 的输入元素作为主体的子元素附加。 −
function resetCreate() {
var Res = document.createElement("INPUT");
Res.setAttribute("type", "reset");
document.body.appendChild(Res);
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

