如何强制 jquery 的 .change 在聚焦时触发文本输入字段上的事件?
我想知道我的
<input type="text">
字段在编辑过程中是否发生了变化,而不仅仅是在模糊时。如何使用 JQuery 来“很好”地实现这一点?我最好的想法是检查每个 keydown() 事件是否有任何更改,然后触发 ie change() 如果是这样。这可以做得更好吗?
I would like to know if my
<input type="text">
field is changed during edition, not only when it's blured. How to achieve this "nicely" using JQuery? My best idea is to check on every keydown() event if anything has changed, then trigger i.e. change() if so. Can this be done better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是真的,但我建议使用 keyup,因为此时该值将落后 1 个击键。
示例:
用户类型:“blah”,“h”的 keydown 将返回值“bla”,因为该值在技术上尚未更改。另外,如果他们按住按键产生重复字符怎么办?
如果您担心的话,那么 keyup 在浏览器中实际上并不昂贵。
你到底想要完成什么,我可以用一个更好的例子来编辑它。
Not really, but I would suggest using keyup, because the value will be 1 keystroke behind at that point.
Example:
User types: "blah", keydown for the "h" would return the value "bla" because the value hasn't technically changed yet. Plus what if they hold down the key yielding repeating characters?
keyup isn't expensive in the browser really if thats what you're worried about.
What are you trying to accomplish exactly and I can edit this with a better example.