HTMLFormElement: sự kiện reset
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Sự kiện reset được kích hoạt khi một <form> được đặt lại.
Cú pháp
Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc đặt một thuộc tính trình xử lý sự kiện.
js
addEventListener("reset", (event) => { })
onreset = (event) => { }
Loại sự kiện
Một Event chung.
Ví dụ
Ví dụ này sử dụng EventTarget.addEventListener() để lắng nghe sự kiện reset của biểu mẫu, và ghi lại Event.timeStamp hiện tại mỗi khi điều đó xảy ra.
HTML
html
<form id="form">
<label>Trường kiểm tra: <input type="text" /></label>
<br /><br />
<button type="reset">Đặt lại biểu mẫu</button>
</form>
<p id="log"></p>
JavaScript
js
const form = document.getElementById("form");
const log = document.getElementById("log");
function logReset(event) {
log.textContent = `Biểu mẫu đã được đặt lại! Timestamp: ${event.timeStamp}`;
}
form.addEventListener("reset", logReset);
Kết quả
Đặc điểm kỹ thuật
| Specification |
|---|
| HTML> # event-reset> |
Tương thích trình duyệt
Xem thêm
- Phần tử HTML
<form>