TextFormat: rangeEnd property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Thuộc tính rangeEnd của giao diện TextFormat cho biết vị trí kết thúc của phạm vi văn bản cần được định dạng với định dạng văn bản đã cho.

Giá trị

Một Number.

Ví dụ

Đọc phạm vi văn bản cần được định dạng

Ví dụ sau cho thấy cách sử dụng thuộc tính rangeStartrangeEnd của sự kiện textformatupdate để xác định phạm vi văn bản cần được định dạng. Lưu ý rằng callback của trình nghe sự kiện trong ví dụ này chỉ được gọi khi sử dụng cửa sổ IME để soạn thảo văn bản.

html
<div id="editor"></div>
js
const editorEl = document.getElementById("editor");
const editContext = new EditContext(editorEl);
editorEl.editContext = editContext;

editContext.addEventListener("textformatupdate", (e) => {
  const formats = e.getTextFormats();

  for (const format of formats) {
    console.log(
      `IME wants to apply formatting between ${format.rangeStart} and ${format.rangeEnd}.`,
    );
  }
});

Thông số kỹ thuật

Specification
EditContext API
# dom-textformat-rangeend

Tương thích trình duyệt

Xem thêm