input
O evento input do
DOM é disparado sincronicamente quando o valor de um elemento <input>
, <select>
, ou <textarea>
é alterado. (Para elementos input com type=checkbox
ou type=radio
, o evento input
não é disparado quando o usuário clica no elemento, porque o valor do atributo não é alterado.) Além disso, o evento é disparado no contenteditable
editors quando o seu conteúdo é alterado. Nesse caso, O alvo do evento é o elemento host da edição. Se houver dois ou mais elementos que tenha contenteditable
como true, o "host de edição" é o elemento antepassado mais próximo cujo pai não é editável. Similarmente, ele também é disparado no element raiz do designMode
editors.
Informações gerais
- Specification
- HTML5, DOM Level 3 Events
- Interface
Event
,InputEvent
(en-US)- Bubbles
- Yes
- Cancelable
- No
- Target
- Element
- Default Action
- The value or the content is modified.
Propriedades
Property | Type | Description |
---|---|---|
target Somente leitura |
EventTarget |
The event target (the topmost target in the DOM tree). |
type Somente leitura |
DOMString |
The type of event. |
bubbles Somente leitura |
Boolean |
Whether the event normally bubbles or not. |
cancelable Somente leitura |
Boolean |
Whether the event is cancellable or not. |
Compatibilidade dos navegadores
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes)[1] | 9[2] | (Yes)[3] | (Yes) |
immediately after compositionupdate |
(Yes) | (Yes) | 12 (12) | (Yes) | 15 | (Yes) |
on contenteditable element |
(Yes) | (Yes) | 14 (14) | Não suportado[4]
|
15 | (Yes) |
when designMode is "on" |
(Yes) | ? | 14 (14) | Não suportado | 15 | (Yes) |
data |
? | ? | Não suportado | ? | ? | ? |
isComposing |
Não suportado | ? | 31 (31) | Não suportado | Não suportado | Não suportado |
<select> | (Yes) | Não suportado | 49 (49) | Não suportado | ? | ? |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | ? | ? | (Yes) |
immediately after compositionupdate |
? | ? | (Yes) | 12.0 (12) | ? | ? | ? |
on contenteditable element |
? | (Yes) | ? | 14.0 (14) | ? | ? | (Yes) |
when designMode is "on" |
? | ? | ? | 14.0 (14) | ? | ? | ? |
data |
? | ? | ? | Não suportado | ? | ? | ? |
isComposing |
Não suportado | Não suportado | ? | 31.0 (31) | Não suportado | Não suportado | Não suportado |
<select> | ? | (Yes) | ? | Não suportado | ? | ? | ? |
[1] Prior to Gecko 12.0 (Firefox 12.0 / Thunderbird 12.0 / SeaMonkey 2.9), Gecko didn't fire input events while composition was ongoing using IMEs or when dead keys were used on Mac OS X.
[2] IE 9 does not fire an input event when the user deletes characters from an input (e.g. by pressing Backspace or Delete, or using the "Cut" operation).
[3] Prior to Opera 15, Opera did not fire an input event after dropping text in an input field.
[4] The event target is the innermost element at the caret position.
Veja também
Also the change
event is related. change
fires less often than input
– it only fires when the changes are committed by the user.