[英]Onchange event that does not wait for input box to lose focus
The onchange
event for a HTML input box does not fire until the textbox loses focus. 在文本框失去焦点之前,不会触发HTML输入框的
onchange
事件。 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/ 这是失去焦点后触发
onchange
的示例: http : //jsfiddle.net/McjqW/
You are looking for the onkeypress
or onkeydown
event. 您正在寻找
onkeypress
或onkeydown
事件。 Note that this event is not standard, and different browsers may expose this functionality under different names. 请注意,此事件不是标准事件,并且不同的浏览器可能以不同的名称公开此功能。 The DOM level 3 standard defines a
keypress
event which would be "the" answer, but again I can't vouch for browser support. DOM 3级标准定义了一个
keypress
事件,该事件将是“ the”答案,但是同样,我不能保证浏览器的支持。
Update: onkeypress
reportedly enjoys wide support . 更新: 据报道,
onkeypress
得到了广泛的支持 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.