With jQuery, how do I capitalize the first letter of a text field while the user is still editing that field?

后端 未结 21 2437
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 16:26

I\'m looking for an example of how to capitalize the first letter of a string being entered into a text field. Normally, this is done on the entire field with a function, r

21条回答
  •  迷失自我
    2020-11-27 17:06

    With Javascript you can use:

    yourtext.substr(0,1).toUpperCase()+yourtext.substr(1);
    

    If by chance you're generating your web page with PHP you can also use:

    
    

提交回复
热议问题