在 Chrome 中使用 jquery 的文本输入时未触发更改事件
我在文本输入上遇到 jquery 更改事件问题,该事件在 Firefox 和 IE 中按预期工作,但在 Chrome 中却不行。我还在文本输入上有一个 keyup 事件,用于在输入时操作输入,但是当输入完成后,我需要运行一些额外的代码。我尝试使用“模糊”事件和“焦点”事件作为替代品,就像这里有人建议的那样,但后来我根本无法改变焦点——输入总是以某种方式将其夺回。这是代码:
$('.textInput').keyup(function(event) { /* do stuff */ });
$('.textInput').change(function(event) { alert('Changed!'); /* do other stuff */ });
和 html:
<input type="text" class="textInput" value="" />
我正在使用 jQuery 1.6.3。任何建议将不胜感激。 H.
I have a problem with a jquery change event on a text input that works as expected in Firefox and IE but not in Chrome. I also have a keyup event on the text input to manipulate the input as it is entered, but when the input is done I need to run some extra code. I tried using the 'blur' event and the 'focusout' event as someone here had suggested as a substitute, but then I couldn't change focus at all -- the input kept grabbing it back somehow. Here is the code:
$('.textInput').keyup(function(event) { /* do stuff */ });
$('.textInput').change(function(event) { alert('Changed!'); /* do other stuff */ });
and the html:
<input type="text" class="textInput" value="" />
I am using jQuery 1.6.3. Any suggestions would be greatly appreciated.
H.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除非输入焦点切换到其他控件,否则更改事件不会触发
The change event will not fire unless the input focus switched to other controls
您可以使用像超级按钮一样工作的
input
事件:来源:https:// gist.github.com/brandonaaskov/1596867
You can use the
input
event that works like a charm:Source: https://gist.github.com/brandonaaskov/1596867
实际上,Google Chrome 上有一个错误,如果“keyup”事件更改了某些内容,则导致“更改”事件不会触发:
https://code.google.com/p/chromium/issues/detail?id=92492
该问题似乎自 5 月 2 日起就已开放, 2013年。
Actually, there's a bug on Google Chrome that causes the 'change' event to not fire if something has been changed by the 'keyup' event:
https://code.google.com/p/chromium/issues/detail?id=92492
The issue seems to be open since May 2, 2013.