input输入框输入小写字母自动转换成大写字母

input输入框输入小写字母自动转换成大写字母有两种方法

1.用js onkeyup事件,即时把字母转换为大写字母:

html里input加上

 <input type="text" id="txt1" value="" onkeyup="toUpperCase(this)"/>

js写函数

function toUpperCase(obj)
 {
 obj.value = obj.value.toUpperCase()
 }

这种方法虽然可以,但是输入汉字的时候会受到干扰,还有一种更好的方法

加css

 <input type="text" id="txt1" value="" style="text-transform:uppercase"/>
原文地址:https://www.cnblogs.com/leiting/p/7724631.html