EditContext: EditContext() コンストラクター
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
EditContext() コンストラクターは、新しい EditContext オブジェクトを返します。
構文
js
new EditContext()
new EditContext(options)
引数
options省略可-
以下のプロパティを持つ、省略可能なオブジェクトです。
text-
EditContextのテキストの初期値として設定する文字列です。 selectionStart-
EditContextの選択範囲の始点の初期値として設定する数値です。 selectionEnd-
EditContextの選択範囲の終点の初期値として設定する数値です。
例
>EditContext オブジェクトを生成する
以下の例では、初期値としてテキスト "Hello world!" を格納し、このテキスト全体を選択した新しい EditContext オブジェクトを生成します。
html
<div id="editor"></div>
js
const initialText = "Hello world!";
const editContext = new EditContext({
text: initialText,
selectionStart: 0,
selectionEnd: initialText.length,
});
const editorElement = document.getElementById("editor");
editorElement.editContext = editContext;
console.log(
`EditContext object ready. Text: ${editContext.text}. Selection: ${editContext.selectionStart} - ${editContext.selectionEnd}.`,
);
仕様書
| Specification |
|---|
| EditContext API> # dom-editcontext-constructor> |
ブラウザーの互換性
関連情報
- 属する
EditContextインターフェイス