表单重置后的表单onreset事件

时间:2014-01-28 19:43:22

标签: javascript html forms events reset

这是一个示例表单:

<!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>

1 个答案:

答案 0 :(得分:1)

试试吧

function myFunction() {
        setTimeout(function () {
            alert("The form was reset!");}, 100); 

        }