InputEvent: thuộc tính inputType
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
* Some parts of this feature may have varying levels of support.
Thuộc tính chỉ đọc inputType của giao diện InputEvent trả về loại thay đổi được thực hiện đối với nội dung có thể chỉnh sửa. Các thay đổi có thể bao gồm, ví dụ, chèn, xóa và định dạng văn bản.
Giá trị
Một chuỗi chứa loại đầu vào đã được thực hiện. Có nhiều giá trị có thể, chẳng hạn như insertText, deleteContentBackward, insertFromPaste, và formatBold. Để biết danh sách đầy đủ các loại đầu vào có sẵn, xem phần Thuộc tính của đặc tả Input Events Level 2.
Ví dụ
Ví dụ này ghi nhật ký inputType cho sự kiện đầu vào trên một <div> có thể chỉnh sửa.
HTML
<p id="log">Input type:</p>
<div contenteditable="true" class="sample-text">
<p>
Some sample text. Try inserting line breaks, or deleting text in different
ways, or pasting different content in.
</p>
<hr />
<ul>
<li>A sample</li>
<li>bulleted</li>
<li>list.</li>
</ul>
<p>Another paragraph.</p>
</div>
CSS
.sample-text {
margin: 20px;
padding: 20px;
border: 2px dashed red;
}
JavaScript
const log = document.getElementById("log");
const editable = document.querySelector("div[contenteditable]");
editable.addEventListener("input", logInputType);
function logInputType(event) {
log.textContent = `Input type: ${event.inputType}`;
}
Kết quả
Hãy thử chỉnh sửa văn bản bên trong <div> và xem điều gì xảy ra.
Note: Xem thêm bộ kiểm tra InputEvent của Masayuki Nakano để có ví dụ chi tiết hơn.
Đặc điểm kỹ thuật
| Thông số kỹ thuật |
|---|
| UI Events> # dom-inputevent-inputtype> |