我将用户输入视为时间,因此页面上有 2 个文本框。 第一个代表小时,第二个代表分钟。
我的验证是:-
文本框中只能输入 2 个数字。
第一个文本框仅接受最多 24 个数字
第二个文本框仅接受 60 以内的数字
$(".TO").on('keyup keypress blur change', function (e) {
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
} else {
if ($(this).val().length >= parseInt(2) && (e.which != 8 && e.which != 0)) {
return false;
}
}
});
我陷入第二次和第三次验证?
最佳答案
尝试使用 max
属性,第一次输入时设置为 "24"
,第二次设置为 "60"
输入
$(".TO").on('keyup keypress blur change', function (e) {
if (+this.value > +this.max) {
this.value = this.max
}
});
jsfiddle http://jsfiddle.net/8tn9h5cu/3/
关于javascript - Jquery - 文本框接受不超过 24 和 60 的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33251354/