InputEvent:data 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
InputEvent
接口中的只读属性 data
返回插入字符的字符串。如果更改未插入文本(例如删除字符时),则其可能为空字符串。
值
一个字符串。
示例
在下面的简单示例中,我们在 input 事件上设置了一个事件监听器,任何对 <input>
元素的文本更改都会被 InputEvent.data
获取,使用 Node.textContent
属性将其插入到段落中。
html
<p>Some text to copy and paste.</p>
<input type="text" />
<p class="result"></p>
js
const editable = document.querySelector("input");
const result = document.querySelector(".result");
editable.addEventListener("input", (e) => {
result.textContent = `输入的文字:${e.data}`;
});
规范
Specification |
---|
Input Events Level 2 # dfn-data |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.