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> .

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.

注意 : See also Masayuki Nakano's InputEvent test suite 了解更详细范例。

规范

规范 状态 注释
UI Events
The definition of 'inputType' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

元数据

  • 最后修改: