insus

在系统中,有一个文本框,要求输入大写字母。但是用户不自觉,只好在程序来控制了。

在网页中,拉一个TextBox控件:

<asp:TextBox ID="TextBoxSeriesNumber" runat="server"></asp:TextBox>


写Javascript脚本,可使用onkeyup事件,即时把字母转换为大写字母:

View Code
<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样式属性说明:

 

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-08-08
  • 2021-07-29
  • 2022-02-15
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-23
  • 2022-01-02
  • 2022-12-23
  • 2021-12-02
  • 2022-01-01
  • 2022-01-16
相关资源
相似解决方案