oninput event

Definition and Usage

The oninput event occurs when the element receives user input.

This event occurs when the value of the <input> or <textarea> element changes.

Tip:This event is similar to onchange ɗanar。Difference is that the oninput event occurs immediately after the element value changes, while onchange occurs when the element loses focus and the content changes. Another difference is that the onchange event also applies to <select> elements.

Instance

Example 1

When the user writes content in the <input> field, execute JavaScript:

<input type="text" oninput="myFunction()">

Try It Yourself

Example 2

Range Slider - How to Dynamically Update Slider Value:

<input type="range" oninput="myFunction(this.value)">

Try It Yourself

Syntax

In HTML:

<element oninput="myScript">

Try It Yourself

In JavaScript:

object.oninput = function(){myScript};

Try It Yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("input", myScript);

Try It Yourself

Note:Internet Explorer 8 or earlier versions do not support addEventListener() Method

Technical Details

Bubbling: 支持
Cancelable: Not Supported
Event Type: Event, InputEvent
Supported HTML Tags: <input type="color">, <input type="date">, <input type="datetime">, <input type="email">, <input type="month">, <input type="number">, <input type="password">, <input type="range">, <input type="search">, <input type="tel">, <input type="text">, <input type="time">, <input type="url">, <input type="week"> kuma <textarea>
DOM 版本: Level 3 Events

浏览器支持

表中的数字注明了完全支持该事件的首个浏览器版本。

事件 Chrome IE Firefox Safari Opera
oninput 支持 9.0 4.0 5.0 支持