• JS 实现数据分割1,123,456


            <asp:TextBox ID="txt2" runat="server" CssClass="decimalInput_R" onkeydown="decimalInput(this, 8, 5)" onkeyup="decimalFormat(this)"></asp:TextBox>

    /*
    ==================================================================
    decimal类型数据的输入检查

    element:input text
    dotLeft:整数部分位数
    dotRight:小数部分位数
    ==================================================================
    */
    function decimalInput(element, dotLeft, dotRight) {
        if( (event.keyCode == 13 || event.keyCode == 8 || (event.keyCode == 110 && !hasChar(element.value, ".")))
             || (((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105))
                    && decimalLength(element.value, dotLeft, dotRight) )) {
            event.returnValue = true;
        } else {
            event.returnValue = false;
        }
    }

    /*
    ==================================================================
    Decimal数据类型数据的格式化
    ==================================================================
    */
    function decimalFormat(element) {
        if ((event.keyCode >= 48 && event.keyCode <= 57)
            || (event.keyCode >= 96 && event.keyCode <= 105)
            || event.keyCode == 13|| event.keyCode == 8
            || event.keyCode == 110) {
            var value = element.value;
            if(value != "") {
                var arr = value.split(".");
                if(arr.length == 1) {
                    var arrInt = arr[0].split("");
                    var newValue = arrInt[arrInt.length-1];
                    var count = 0;
                    for(i = arrInt.length - 2; i >= 0 ; i--) {
                        if(arrInt[i] === ",") {
                            continue;
                        }
                        count++;
                        if(count === 3) {
                            newValue = "," + newValue;
                            count = 0;
                        }
                        newValue = arrInt[i] + newValue;
                    }
                    if(typeof(newValue) != "undefined") {
                        element.value = newValue;
                    }
                    return;
                }
            }
        }
    }

  • 相关阅读:
    jquery设置控件位置的方法
    Redis学习(1)——下载与配置[转]
    Redis中redis.conf里面配置详解
    JAVA 上加密算法的实现用例,MessageDigest介绍
    JAVA的StringBuffer类[转]
    java synchronized详解[转]
    windows命令行下批量拷贝同一后缀的文件到另外一个目录
    批处理for命令详解(转)
    myeclipse10.X以上的破解方法
    jquery的get()方法
  • 原文地址:https://www.cnblogs.com/hyd309/p/1522710.html
Copyright © 2020-2023  润新知