![codecamp](https://atts.w3cschool.cn/attachments/image/20230811/1691741920856601.png)
HTML DOM Form reset() 方法
Form reset() 方法
![Form 对象参考手册](https://atts.w3cschool.cn/attachments/image/up.gif)
定义和用法
reset() 方法可以重置表单所有元素的值 (与点击 Reset 按钮效果一致)。
语法
formObject.reset()
浏览器支持
所有主要浏览器都支持 reset() 方法
实例
实例
创建表单的重置按钮:
<html>
<head>
<script>
function formReset()
{
document.getElementById("frm1").reset();
}
</script>
</head>
<body>
<form id="frm1">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="button" onclick="formReset()" value="Reset form">
</form>
</body>
</html>
<head>
<script>
function formReset()
{
document.getElementById("frm1").reset();
}
</script>
</head>
<body>
<form id="frm1">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="button" onclick="formReset()" value="Reset form">
</form>
</body>
</html>
尝试一下 »
![Form 对象参考手册](https://atts.w3cschool.cn/attachments/image/up.gif)