这是一个示例表单:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Form onreset</title>
</head>
<body>
<form onreset="myFunction();">
<input type="text" name="fname">
<input type="text" name="lname">
<button type="reset" value="Reset">Reset</button>
</form>
<script>
function myFunction() {
alert("The form was reset!");
}
</script>
</body>
</html>
当我单击重置按钮时,首先触发表单 onreset 事件,即在重置表单字段之前出现警报消息。表单字段休息后怎么会发生这种情况?
我也尝试过以下方法,但没有成功:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Form onreset</title>
</head>
<body>
<form>
<input type="text" name="fname">
<input type="text" name="lname">
<button type="reset" value="Reset" onclick="myFunction();">Reset</button>
</form>
<script>
function myFunction() {
alert("The form was reset!");
}
</script>
</body>
</html>
最佳答案
尝试一下
function myFunction() {
setTimeout(function () {
alert("The form was reset!");}, 100);
}
关于javascript - Form onreset 表单重置后的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21415267/