Capitalize first character of user input in real time with JQuery

后端 未结 8 1250
-上瘾入骨i
-上瘾入骨i 2021-02-14 13:15

I am trying to auto-capitalize the first character of a textarea/input that the user inputs. The first attempt looked like this:

$(document).ready(function() {
         


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-14 14:11

    It would be much easier to use CSS in this case:

    input{
        text-transform: capitalize;
    }
    

    Update: this works when you don't want to capitalize the first letter of every word, but only the first letter of the first word:

    input::first-letter{
        text-transform: uppercase;
    }
    

提交回复
热议问题