Change Input to Upper Case

前端 未结 15 772
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 22:02

JS:



        
15条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 22:42

    This answer has a problem:

    style="text-transform: uppercase"
    

    it also converts the place holder word to upper case which is inconvenient

    placeholder="first name"
    

    when rendering the input, it writes "first name" placeholder as uppercase

    FIRST NAME
    

    so i wrote something better:

    onkeypress="this.value = this.value + event.key.toUpperCase(); return false;"
    

    it works good!, but it has some side effects if your javascript code is complex,

    hope it helps somebody to give him/her an idea to develop a better solution.

提交回复
热议问题