JS:识别按键中的点或删除
如果用户按下点(在标准键盘或数字块上),我想执行一些代码。但如果我把它放在 Keycode (110) 上,这和删除按钮是一样的。
我如何认出他们?
感谢您的帮助!
I'd like to execute some code if the user presses the dot (on standard keybord or on numblock). But if I take it over Keycode (110), this is the same like the delete button.
How do I recognize them?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除键(通常在箭头上方)是 46,小键盘十进制是 110,键盘句号是 190。
这是一个很好的页面,可以了解键码是什么:http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac- 25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx
如果这不能回答您的问题,请重新措辞,因为它有点令人困惑您正在寻找的内容。
Delete key (usually above arrows) is 46, numpad decimal is 110, and the keyboard period is 190.
This is a pretty good page to know what keycodes are what: http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx
If this doesn't answer your question, please rephrase it as it's a little confusing what you are looking for.
使用现代 JS!
使用
event.key === "." || event.key ===“删除”
,而不是任意数字代码!Use modern JS!
Use
event.key === "." || event.key === "Delete"
, rather than arbitrary number codes!只允许使用点和数字
it's only allow dot and numbers