Jquery - 文本框接受不超过 24 和 60 的数字

Jquery - Textbox accepts numbers not more than 24 & 60

我将用户输入作为时间,所以我在页面上有 2 个文本框。 第一个是小时,第二个是分钟。

我的验证是:-

FIDDLE

$(".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" input,第二个设置为 "60" input

$(".TO").on('keyup keypress blur change', function (e) {
    if (+this.value > +this.max) {
      this.value = this.max
    }
});

jsfiddle http://jsfiddle.net/8tn9h5cu/3/