How to make everything in a textfield be capital letters / uppercase?

后端 未结 5 699
不知归路
不知归路 2021-02-07 02:37

I want to make everything I write in a textfield to be capital letters. As I write, not after losing focus.

How do I do this using jQuery?

5条回答
  •  深忆病人
    2021-02-07 02:53

    To build on @Gazler's answer, an enhanced solution that better handles modifier keys ( assuming that you have a placeholder of mixed case and cannot set text-transform: uppercase; ):

    $('.search-input input[type=text]').keyup(function() {
        var v = $(this).val();
        var u = v.toUpperCase();
        if( v != u ) $(this).val( u );
    })
    

提交回复
热议问题