How to change lowercase chars to uppercase using the 'keyup' event?

后端 未结 12 1827
失恋的感觉
失恋的感觉 2021-01-31 01:58

My goal is to use the jQuery event .keyup() to convert inputted lowercase chars to uppercase.

How can I achieve this?

12条回答
  •  深忆病人
    2021-01-31 02:26

    Plain ol' javascript:

    var input = document.getElementById('inputID');
    
    input.onkeyup = function(){
        this.value = this.value.toUpperCase();
    }
    

    Javascript with jQuery:

    $('#inputID').keyup(function(){
        this.value = this.value.toUpperCase();
    });
    

提交回复
热议问题