不要让用户在HTML5输入类型编号中键入句点字符 [英] Don't let a user type the period character in an HTML5 input type number
本文介绍了不要让用户在HTML5输入类型编号中键入句点字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以现在用户可以在HTML5 input type =number的数字字段中插入一个十进制值。我想阻止它,所以如果用户键入5.1,它将在文本框中插入51。
So right now the user is able to insert a decimal value in the number field of the HTML5 input type="number". I want to prevent that, so if a user types "5.1" it will insert "51" in the textbox.
有没有办法做到这一点?谢谢!
Is there any way to do this? Thanks!
推荐答案
明确答案如下:
function preventDot(e) {
var key = e.charCode ? e.charCode : e.keyCode;
if (key == 46) {
e.preventDefault();
}
}
并在按键上绑定
这篇关于不要让用户在HTML5输入类型编号中键入句点字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文