2014-01-28 78 views
1

下面是一個樣表:形式onreset事件復位

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

http://stackoverflow.com/questions/8152904/call-a-function-after-form的可能的複製-重啓 – talemyn

回答

1

試試吧

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

     }