在Webkit / Chrome中检测HTML5数字控件更改的事件? [英] Event to detect change of an HTML5 number control in Webkit/Chrome?

查看:171
本文介绍了在Webkit / Chrome中检测HTML5数字控件更改的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML5为我们提供了一些新的输入元素,例如< input type = number> 。这在Chrome中作为一个文本框呈现,在文本框内有两个循环按钮,用于递增和递减框内的数字值。



对于个人爱好项目,我使用这个控件。然而,我坚持一个问题:

有没有一种方法可以检测使用javascript事件更改的值?我期待着 onChange 事件触发,但没有这样的运气。另外, onClick 只会在点击文本框内容时触发,而不是点击循环按钮时触发。



任何创意? (除了:嘿,它是HTML5表单,不要期望任何工作!)

编辑:正如mikerobi指出的那样,只要元素失去焦点,onChange事件就会触发。仍然不是我在找什么,所以其他的意见和建议是值得欢迎的!

解决方案

bugreport的结果: t修正因为当按下这些按钮时触发输入事件。它是HTML5规范的一部分。所以问题解决了,感谢mikerobi的提交文件。


HTML5 gives us some new input elements to play with, such as <input type=number>. This renders (in Chrome) as a textbox with two cycle buttons inside the textbox, for incrementing and decrementing the numeric value inside the box.

For a personal hobby project, I'm using this control. However, I'm stuck with one issue:

Is there a way to detect the value being changed using a javascript event? I had expected the onChange event to fire, but no such luck. Also, onClick only triggers when the textbox content is clicked, not when the cycle buttons are clicked.

Any ideas? (apart from: hey, it's HTML5 Forms, don't expect anything to work yet!)

Edit: As mikerobi points out below, the onChange event does fire as soon as the element loses focus. Still not quite what I'm looking for, so other comments and suggestions are welcome!

解决方案

Result of the bugreport: Won't Fix, because the input event is fired when those buttons are pressed. It's part of the HTML5 spec. So problem solved, thanks to mikerobi's sugestion to file the report.

这篇关于在Webkit / Chrome中检测HTML5数字控件更改的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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