inputType
只读特性在
InputEvent
interface returns the type of change made to editible content. Possible changes include for example inserting, deleting, and formatting text.
var aString = inputEvent.inputType;
A
DOMString
containing the type of input that was made. There are many possible values, such as
insertText
,
deleteContentBackward
,
insertFromPaste
,和
formatBold
. For a complete list of the available input types, see the
Attributes section of the Input Events Level 1 spec
.
This example logs the
inputType
for
input events
on an editable
<div>
.
<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>
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.
注意 : See also Masayuki Nakano's InputEvent test suite 了解更详细范例。
| 规范 | 状态 | 注释 |
|---|---|---|
|
UI Events
The definition of 'inputType' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
inputType
|
Chrome 60 | Edge 79 | Firefox 66 | IE 不支持 No | Opera 47 | Safari 10.1 | WebView Android 60 | Chrome Android 60 | Firefox Android 66 | Opera Android 44 | Safari iOS 10.3 | Samsung Internet Android 8.0 |
insertFromPasteAsQuotation
input type
|
Chrome 不支持 No | Edge 不支持 No | Firefox 67 | IE 不支持 No | Opera 不支持 No | Safari ? | WebView Android 不支持 No | Chrome Android 不支持 No | Firefox Android 67 | Opera Android 不支持 No | Safari iOS ? | Samsung Internet Android 不支持 No |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
InputEvent
data
dataTransfer
inputType
isComposing