# input 中监听值的变化是在监听什么事件
Issue
欢迎在 Gtihub Issue 中回答此问题: Issue 215 (opens new window)
Author
可以实时监听值的变化的事件有以下几种
- keypress
- keydown
- keyup
- input
注: onChange
无法做到实时监听,因为 onChange 需要失去焦点才能触发
Author
oninput 不用考虑是否失去焦点,不管 js 操作还是键盘鼠标手动操作,只要 HTML 元素属性发生改变即可立即捕获到
Author
onchange:
Supported HTML tags:
<input type="checkbox">, <input type="file">, <input type="password">, <input type="radio">, <input type="range">, <input type="search">, <input type="text">, <select> and <textarea>
The onchange attribute fires the moment when the value of the 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. The other difference is that the onchange event also works on
Author
@CaiyueDamowang 测试了好像不行
Author
@CaiyueDamowang 测试了好像不行
嗯,不行。。 在 html 标签中 onchange 可以在失去焦点触发
Author
低版本浏览器 function onPropertyChange(event){console.log(event.srcElement.value)}
ie10 以上 function onInput(event){console.log(event.srcElement.value)}
Author
input 事件
Author
oninput 实时触发,onchange 失去焦点时触发