TextEvent
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Giao diện TextEvent là giao diện sự kiện UI cũ để báo cáo các thay đổi đối với các phần tử UI văn bản.
Note:
Các sự kiện TextEvent đã được thay thế bởi các sự kiện như input, beforeinput, keypress, keyup và keydown.
Thuộc tính phiên bản
Giao diện này cũng kế thừa các thuộc tính từ phần tử cha UIEvent, và gián tiếp từ Event.
TextEvent.dataRead only Đã lỗi thời-
Chỉ ra dữ liệu liên quan đến sự kiện.
Phương thức phiên bản
TextEvent.initTextEvent()Đã lỗi thời-
Điền các giá trị của
TextEventmới này với các tham số đã cho.
Danh sách sự kiện
Dưới đây là danh sách tất cả các sự kiện TextEvent:
textinput
Ví dụ
>Lắng nghe sự kiện nhập văn bản
Bạn có thể đăng ký trình nghe cho các sự kiện nhập văn bản bằng EventTarget.addEventListener() như sau:
element.addEventListener("textInput", (event) => {
// …
});
Trình ghi log đơn giản hiển thị sự kiện đầu vào
Ví dụ này lắng nghe một số sự kiện được kích hoạt trên input, bao gồm textInput. Loại sự kiện và dữ liệu sự kiện được ghi lại, cho phép bạn xem nơi textInput được phát ra so với các sự kiện khác như những sự kiện được tạo bởi các phím bấm.
HTML
<input placeholder="Enter some text" name="name" />
JavaScript
const input = document.querySelector("input");
input.addEventListener("keypress", updateValue);
input.addEventListener("keyup", updateValue);
input.addEventListener("keydown", updateValue);
input.addEventListener("input", updateValue);
input.addEventListener("beforeinput", updateValue);
input.addEventListener("textInput", updateValue);
function updateValue(e) {
log(`${e.type}: ${e.data}`);
}
Kết quả
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| UI Events> # legacy-textevent-events> |