不等待输入框失去焦点的onchange事件
HTML 输入框的 onchange
事件在文本框失去焦点之前不会触发。有没有办法让它在内容发生变化时立即触发?
下面是焦点丢失后触发 onchange
的示例: http://jsfiddle.net/McjqW/< /a>
The onchange
event for a HTML input box does not fire until the textbox loses focus. Is there a way to make it fire as soon as the contents change?
Here's an example of onchange
firing after focus loss: http://jsfiddle.net/McjqW/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 onkeyup 代替
http://jsfiddle.net/McjqW/1/
You can use onkeyup instead
http://jsfiddle.net/McjqW/1/
您正在寻找
onkeypress
或onkeydown
事件。请注意,此事件不是标准的,不同的浏览器可能会以不同的名称公开此功能。 DOM level 3 标准定义了keypress
事件这将是“答案”,但我再次不能保证浏览器支持。更新:
onkeypress
据报道获得广泛支持 。You are looking for the
onkeypress
oronkeydown
event. Note that this event is not standard, and different browsers may expose this functionality under different names. The DOM level 3 standard defines akeypress
event which would be "the" answer, but again I can't vouch for browser support.Update:
onkeypress
reportedly enjoys wide support.您需要 HTML5
input
事件。它不是完全跨浏览器,但有一个针对 IE < 的解决方法。 9,这是唯一没有它的主要浏览器。请参阅此处和此处。You need the HTML5
input
event. It's not quite fully cross-browser but there's a workaround for IE < 9, which is the only major browser that doesn't have it. See here and here.