InputEvent.inputType
inputType
は InputEvent
インターフェイスの読取専用プロパティで、編集可能なコンテンツの変更が行われた種別を返します。変更は例えば挿入、削除、テキスト整形などがあります。
構文
var aString = inputEvent.inputType;
値
入力された入力種別を含む DOMString
。 insertText
, deleteContentBackward
, insertFromPaste
, formatBold
など、多くの値が考えられます。利用可能な入力種別の完全なリストは、Input Events Level 1 仕様の Attributes の章を参照してください。
例
HTML
<p id="log">Input type: </p>
<div contenteditable="true" style="margin: 20px;padding: 20px;border:2px dashed red;">
<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>
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}`;
}
結果
Try editing the text inside the <div>
and see what happens.
注: もっと詳細な例として Masayuki Nakano's InputEvent test suite も参照してください。
仕様書
仕様書 | 状態 | 備考 |
---|---|---|
UI Events inputType の定義 |
草案 |
ブラウザーの互換性
BCD tables only load in the browser