Call a function when a user changes the selected option of a <select> element:
<select onchange="myFunction()">
Try it Yourself »
More "Try it Yourself" examples below.
The onchange
event occurs when the value of an HTML element is changed.
Tip: This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus, after the content has been changed. The other difference is that the onchange event also works on <select> elements.
In JavaScript, using the addEventListener() method:
object.addEventListener("change",
myScript);
Try it Yourself »
Bubbles: | Yes |
---|---|
Cancelable: | No |
Event type: | Event |
HTML tags: | <input type="checkbox">, <input type="color">, <input type="date">, <input type="datetime">, <input type="email">, <input type="file">, <input type="month">, <input type="number">, <input type="password">, <input type="radio">, <input type="range">, <input type="search">, <input type="tel">, <input type="text">, <input type="time">, <input type="url">, <input type="week">, <select> and <textarea> |
DOM Version: | Level 2 Events |
Call a function when a user changes the content of an input field:
<input type="text" onchange="myFunction()">
Try it Yourself »
onchange
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!