Convert to uppercase as user types using javascript

后端 未结 12 1557
清酒与你
清酒与你 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:38

    function changeToUpperCase(event,obj) {
        charValue = (document.all) ? event.keyCode : event.which;
        if (charValue!="8" && charValue!="0" && charValue != "27"){
            obj.value += String.fromCharCode(charValue).toUpperCase();
            return false;
        }else{
            return true;
        }
    }
    
    
    

    Edit:

    The most simplest way is by using css:

    #txtId {text-transform:uppercase}
    

提交回复
热议问题