首页 > 文章列表 > 当在HTML中点击表单中的重置按钮时执行脚本?

当在HTML中点击表单中的重置按钮时执行脚本?

471 2023-09-12

当表单被重置时,onreset 属性会触发。您可以尝试运行以下代码来实现onreset属性 −

示例

<!DOCTYPE html>
<html>
   <body>
      <form onreset = "display()">
         Student Name:<br>
         <input type = "text" name = "sname">
         <br>
         Student Subject:<br>
         <input type = "text" name = "ssubject">
         <br>
         <input type = "reset" value = "reset">
      </form>
      <script>
         function display() {
            alert("Form reset successfull!");
         }
      </script>
   </body>
</html>