Convert to uppercase as user types using javascript

后端 未结 12 1555
清酒与你
清酒与你 2020-12-13 17:59

I want to convert lowercase chars to uppercase as the user types using javascript. Any suggestions are welcome.

I have tried the following:

$(\"#text         


        
12条回答
  •  失恋的感觉
    2020-12-13 18:29

    While the CSS + Server Side UCase approach is probably "best", here is a Client Side jQuery solution I use when the need arises:

    $("#id").keyup(function() {
        $(this).val($(this).val().replace(/([a-z])/,function(s){return s.toUpperCase()}));
    });
    

    She's not pretty, but she'll get the job done!

提交回复
热议问题