How to make everything lowercase automatically in Javascript as they type it in

后端 未结 6 1227
既然无缘
既然无缘 2021-02-13 02:35

How do I make all of the characters of a text box lowercase as the user types them into a text field in Javascript?



        
6条回答
  •  野的像风
    2021-02-13 03:33

    This is a mask for the type of validation that you want

    (function($) {
        $.fn.maskSimpleName = function() {
            $(this).css('text-transform', 'lowercase').bind('blur change', function(){
                this.value = this.value.toLowerCase();
            });
        }
    })(jQuery);
    

    The advantage of using it is that the cursor will not go to the end of the input each character entered, as it would if using the a keyup or keupress solution.

    $('#myinput').maskSimpleName();
    

    This is a way to use it.

    Obs: This mask sends the data in lowercase to the server as well.

提交回复
热议问题