这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
DOM
beforeinput
event fires when the value of an
<input>
,
<select>
,或
<textarea>
element is about to be modified. The event also applies to elements with
contenteditable
enabled, and to any element when
designMode
is turned on.
In the case of
contenteditable
and
designMode
, the event target is the
editing host
. If these properties apply to multiple elements, the editing host is the nearest ancestor element whose parent isn't editable.
| 冒泡 | Yes |
|---|---|
| 可取消 | Yes |
| 接口 |
InputEvent
|
| 事件处理程序特性 | None |
| Sync / Async | Sync |
| Composed | Yes |
| 默认动作 | Update the DOM element |
This example logs current value of the element immediately before replacing that value with the new one applied to the
<input>
元素。
<input placeholder="Enter some text" name="name"/> <p id="values"></p>
const input = document.querySelector('input');
const log = document.getElementById('values');
input.addEventListener('beforeinput', updateValue);
function updateValue(e) {
log.textContent = e.target.value;
}
| 规范 | 状态 |
|---|---|
|
UI Events
The definition of 'beforeinput event' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
beforeinput
event
|
Chrome Yes | Edge 79 | Firefox No | IE No | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android No | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
不支持
实验。期望将来行为有所改变。
input
HTMLElement
contentEditable
contextMenu
dir
hidden
innerText
isContentEditable
lang
offsetHeight
offsetLeft
offsetParent
offsetTop
offsetWidth
onabort
onanimationcancel
onanimationend
onanimationiteration
onauxclick
onblur
oncancel
oncanplay
oncanplaythrough
onchange
onclick
onclose
oncontextmenu
oncopy
oncuechange
oncut
ondblclick
ondurationchange
onended
onerror
onfocus
onformdata
ongotpointercapture
oninput
oninvalid
onkeydown
onkeypress
onkeyup
onload
onloadeddata
onloadedmetadata
onloadend
onloadstart
onlostpointercapture
onmousedown
onmouseenter
onmouseleave
onmousemove
onmouseout
onmouseover
onmouseup
onpaste
onpause
onplay
onplaying
onpointercancel
onpointerdown
onpointerenter
onpointerleave
onpointermove
onpointerout
onpointerover
onpointerup
onreset
onresize
onscroll
onselect
onselectionchange
onselectstart
onsubmit
ontouchcancel
ontouchstart
ontransitioncancel
ontransitionend
onwheel
outerText
title