zoukankan      html  css  js  c++  java
  • 文本框中输入小写字母即时转换为大写

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

    在网页中,拉一个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样式属性说明:

  • 相关阅读:
    UI 常用方法总结之--- UITableView
    UITextFiled 通知监听
    ios 本地通知
    AFNetworking 请求头的设置
    UI总结
    gitlab-server环境搭建
    redis 配置文件示例
    搭建spark集群
    kafka集群安装
    zookeeper集群搭建
  • 原文地址:https://www.cnblogs.com/insus/p/2986372.html
Copyright © 2011-2022 走看看