[英]How can I modify the function keydown in javascript to not allow a decimal point?
With this I can write only numbers: 这样我只能写数字:
validaHoraNumero: function(iContTabla,iContFila){
var self = this;
$("#hora_"+iContTabla+"_"+iContFila+"_id").keydown(function (e) {
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || $(this).val().indexOf('.') != -1 || (e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) || (e.keyCode >= 35 && e.keyCode <= 40)) {
return;
}
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
});
},
I need to modify this method to not allow write a decimal point "." 我需要修改此方法以不允许写小数点“。”
How can I do this? 我怎样才能做到这一点? thanks.
谢谢。
Just remove the 190, which is '.' 只需删除190,即“。”。
$("#field").keydown(function (e) {
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 || $(this).val().indexOf('.') != -1 || (e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) || (e.keyCode >= 35 && e.keyCode <= 40)) {
return;
}
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
});
https://jsfiddle.net/s3xqtdax/ https://jsfiddle.net/s3xqtdax/
You can also check this solution: 您还可以检查以下解决方案:
How to allow only numeric (0-9) in HTML inputbox using jQuery? 如何使用jQuery在HTML输入框中仅允许数字(0-9)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.