在系统中,有一个文本框,要求输入大写字母。但是用户不自觉,只好在程序来控制了。
在网页中,拉一个TextBox控件:
<asp:TextBox ID=\"TextBoxSeriesNumber\" runat=\"server\"></asp:TextBox>
写Javascript脚本,可使用onkeyup事件,即时把字母转换为大写字母:
<script type=\"text/javascript\">
window.onload = function () {
var textBox = document.getElementById(\"<%= TextBoxSeriesNumber.ClientID %>\");
textBox.onkeyup = function () {
this.value = this.value.toUpperCase();
};
};
</script>
Demo:
以下内容于15:08分补充:
上面的方法,会有一个问题,就是先显示小写字母,再转变为大写字母。在网上查找其它资料时,又无意中发有一个更好的方法,就是使用CSS来实现:
style=\"text-transform:uppercase;\"
完整应用如下:
有关text-transform样式属性说明:
本文地址:https://www.stayed.cn/item/8069
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我