Call a function when a user writes something in an <input> field:
<input type="text" oninput="myFunction()">
Try it Yourself »
More examples below.
The oninput
event occurs when an element gets input.
The oninput
event occurs when the value of an <input> or <textarea> element is changed.
The oninput
event does NOT occur when a <select> element changes.
The oninput
event is similar to the onchange
event.
The difference is that the oninput
event occurs immediately after the content has been changed, while onchange
occurs when the element loses focus.
In JavaScript, using the addEventListener() method:
object.addEventListener("input",
myScript);
Try it Yourself »
Bubbles: | Yes |
---|---|
Cancelable: | No |
Event type: | Event, InputEvent |
HTML tags: | <input> and <textarea> |
DOM Version: | Level 3 Input Events |
Range slider - how to dynamically update slider value:
<input type="range" oninput="myFunction(this.value)">
Try it Yourself »
oninput
is a DOM Level 3 (2004) feature.
It is fully supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!