input time mask using jquery

后端 未结 5 1468
庸人自扰
庸人自扰 2021-02-06 11:37

I am using meioMask – a jQuery mask plugin to put time mask in a textbox. Here is the JsFiddle. It\'s working well. But I also need to put hh:mm in the textbox, to

5条回答
  •  不思量自难忘°
    2021-02-06 12:28

    using jQuery Masked Input Plugin.

    $.mask.definitions['H'] = "[0-2]";
    $.mask.definitions['h'] = "[0-9]";
    $.mask.definitions['M'] = "[0-5]";
    $.mask.definitions['m'] = "[0-9]";
    $(".timepicker").mask("Hh:Mm", {
        completed: function() {
            var currentMask = $(this).mask();
            if (isNaN(parseInt(currentMask))) {
                $(this).val("");
            } else if (parseInt(currentMask) > 2359) {
                $(this).val("23:59");
            };
        }
    });
    

提交回复
热议问题