Change Input to Upper Case

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

JS:



        
相关标签:
15条回答
  • 2020-12-07 22:39

    I think the most easiest way to do is by using Bootstrap's class ".text-uppercase"

    <input type="text" class="text-uppercase" />
    
    0 讨论(0)
  • 2020-12-07 22:42

    try:

    $('#search input.keywords').bind('change', function(){
        //this.value.toUpperCase();
        //EDIT: As  Mike Samuel suggested, this will be more appropriate for the job
        this.value = this.value.toLocaleUpperCase();
    } );
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题