HTML输入值变化 [英] HTML Input on change of value
问题描述
< input onvaluechange =// do follow .../>
JavaScript属性 onchange
不会触发价值的变化,只有变化,如模糊,焦点等...
编辑:它也不一定是按键。由于自动完成,用户只需鼠标单击自动完成结果即可更改值。这不会触发 onkeydown
事件。
它也不一定是按键。由于自动完成
...以及许多其他非基于键的操作,例如右键单击/粘贴,拖放,撤消/重做,拼写检查调整等。
HTML5定义了一个 oninput
事件来捕获所有直接更改。
不幸的是,今天的浏览器支持并不存在(IE中没有支持,而在其他方面也有一些错误),所以只要你真的需要要检测早于 onchange
的输入值的所有更改是使用 setInterval
添加一个不断与以前的价值。
I have an input tag. This tag does not have the autocomplete feature turned off, thus, one does not necessarily need to release a key to change the value of this field and focus another one. My question is: how can I detect ANY value changes of this particular field, like e. g.
<input onvaluechange="//do following..." />
The JavaScript attribute onchange
does not fire on change of value, only on changes like blur, focus, etc...
EDIT: It also doesn't necessarily be a key press. Due to the autocompletion, the user can simply mouse-click the autocompletion result to change the value. This would not fire an onkeydown
event.
It also doesn't necessarily be a key press. Due to the autocompletion
...and many other non-key-based operations, such as right-click-cut/paste, drag and drop, undo/redo, spellchecker adjustments and so on.
HTML5 defines an oninput
event to catch all direct changes.
Unfortunately browser support today isn't there (no support in IE, and there are some bugs in others), so all you can do if you really need to detect all changes to an input value earlier than onchange
is to use setInterval
to add a poller that constantly compares against the previous value.
这篇关于HTML输入值变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!