运行 ❯
获取您的
自有
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <p>Enter some text in the field below, then press the "Reset form" button to reset the form.</p> <form id="myForm" onreset="myAlertFunction()"> First name: <input type="text" name="fname"> <input type="button" onclick="myResetFunction()" value="Reset form"> </form> <p>The reset() method of the HTML DOM Form Object resets the values of all elements in a form. When this happens, the onreset event fires, which will trigger the alert function.</p> <script> // Reset the text of an element 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"); } </script> </body> </html>