使用字符码仅允许数字并输入密钥 [英] Using charcode to allow only numbers and enter key

查看:78
本文介绍了使用字符码仅允许数字并输入密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的语法:

<input onkeypress="return event.charCode >= 48 && event.charCode <= 57">

我在输入中使用它以仅允许数字. 但是现在我也需要允许回车键,因为我不能再使用按钮提交表单了(由于个人原因).到现在我发现了:

I use it on inputs to allow only numbers. But now i need to allow the enter key too since i can no longer use a button to submit the form(personal reasons).By now i found this:

  event.charCode = 13 // allows enter key

但是我似乎找不到如何构建onkeypress语法的方法.有帮助吗?谢谢.

but i can't seem to find how to build the onkeypress syntax.Any help ? Thank you.

推荐答案

您可以尝试:

onkeypress="return event.charCode >= 8 && event.charCode <= 57"

通过这种方式,您可以输入键,数字..和其他几个字符(字母字符除外).我看不到其他任何方式. 来源:单击

In this way you can allow enter key,numbers..and few other characters,except for alphabetic characters.I don't see any other way. Source: click

这篇关于使用字符码仅允许数字并输入密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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