TextUpdateEvent: text 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

TextUpdateEvent.text 只讀屬性包含在 EditContexttextupdate 事件的更新範圍內插入的文字。

一個 String,其中包含替換 updateRangeStartupdateRangeEnd 索引之間的文字的文字。

示例

使用 textupdate 顯示插入的文字和位置

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

editContext.addEventListener("textupdate", (e) => {
  console.log(
    `The user inserted the text "${e.text}" at index ${e.updateRangeStart}.`,
  );
});

規範

規範
EditContext API
# dom-textupdateevent-text

瀏覽器相容性