Call a function when a form is reset:
<form onreset="myFunction()">
Enter name: <input type="text">
<input type="reset">
</form>
Try it Yourself »
More "Try it Yourself" examples below.
The onreset event occurs when a form is reset.
Event | |||||
---|---|---|---|---|---|
onreset | Yes | Yes | Yes | Yes | Yes |
In JavaScript, using the addEventListener() method:
object.addEventListener("reset",
myScript);
Try it Yourself »
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | Event |
HTML tags: | <form> |
DOM Version: | Level 2 Events |
Display the text that was inserted in a text field before it was reset:
var x = document.getElementById("myInput");
alert("Before reset, the text was: " + x.value);
Try it Yourself »
Using the reset() method of the HTML DOM Form Object to reset the form. When this happens, the onreset event fires, which will trigger an alert function.
// Reset the value of all elements in a form with id="myForm"
function myResetFunction() {
document.getElementById("myForm").reset();
}
// Alert some text when the form is reset
function myAlertFunction() {
alert("The form was reset");
}
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!