HTML输入值变化 [英] HTML Input on change of value

查看:128
本文介绍了HTML输入值变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入标签。此标签没有关闭自动完成功能,因此,不一定需要释放键来更改此字段的值并将其重点放在另一个上。我的问题是:如何检测此特定字段的任何值更改,如e。 G。

 < 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆