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"/>

 

posted @ 2017-10-24 17:13  c-137Summer  阅读(11272)  评论(0编辑  收藏  举报