Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thực thi script khi nút reset trong form được nhấn trong HTML?

Khi form bị reset, thuộc tính onreset kích hoạt. Bạn có thể chạy mã sau để triển khai thuộc tính onreset:

Ví dụ

<!DOCTYPE html>
<html>
  <body>
    <form onreset="display()">
      Tên sinh viên:<br>
      <input type="text" name="sname">
      <br>
      Môn học:<br>
      <input type="text" name="ssubject">
      <br>
      <input type="reset" value="reset">
    </form>
    <script>
      function display() {
        alert("Form reset thành công!");
      }
    </script>
  </body>
</html>