Forcing form text to be lower-case

前端 未结 11 1395
面向向阳花
面向向阳花 2021-02-02 10:16

How could I force the text in the \"username\" text input to be lower-case regardless of what user types?

11条回答
  •  忘了有多久
    2021-02-02 11:19

    @fdiv_bug's answer is good except for the issues mentioned in the comments of their answer. Using the input event instead of the keyup event fixed those issues for me.

    HTML:

    Javascript:

    element.addEventListener('input',function(){this.value=this.value.toLowerCase()});​
    

提交回复
热议问题