HTML maxlength attribute not working on chrome and safari?

前端 未结 7 1675
借酒劲吻你
借酒劲吻你 2020-12-15 15:06


        
相关标签:
7条回答
  • 2020-12-15 16:01

    I solved problem using this jQuery codes:

    $('input[type="number"]').on('keypress', function (e) {
        var maxlength = $(this).prop('maxlength');
        if (maxlength !== -1) {  // Prevent execute statement for non-set maxlength prop inputs
            var length = $(this).val().trim().length;
            if (length + 1 > maxlength) e.preventDefault();
        }
    });
    

    Set maxlength attribute for every input[type="number"] that you want, just like text inputs.

    0 讨论(0)
提交回复
热议问题