1.用 js 的 onkeyup 事件,即时把字母转换为大写字母:
<input type="text" value="" onkeyup="toUpperCase(this);"/>
<script type="text/javascript">
function toUpperCase(obj) {
obj.value = obj.value.toUpperCase()
}
</script>
<input type="text" value="" onkeyup="this.value = this.value.toUpperCase();"/>
2.上面的方法虽然可以,但是在输入汉字的时候会受到干扰,还有一种更好的方法,直接加上 css:
<input type="text" value="" style="text-transform: uppercase;"/>