zoukankan      html  css  js  c++  java
  • Javascript实现真实字符串剩余字数提示

    //文本框剩余字数提示(字符大小)
    function textLimitCheckSj(thisArea, maxLength, SpanId) {
        var str = thisArea.value;
        if (getChrLen(str, maxLength) > maxLength * 2) {
            thisArea.value = str.substring(0, x-1);
        }
        else {
            var varss = '(剩余字数:' + Math.floor((maxLength * 2 - getChrLen(str, maxLength)) / 2) + ')';
            document.getElementById(SpanId).innerHTML = varss;
        }
    }
    function getChrLen(str, maxLength) {
        var realLength = 0, len = str.length, charCode = -1;
        x = 0;
        for (; (x < len) && (realLength <=maxLength * 2); x++) {
            charCode = str.charCodeAt(x);
            if (charCode >= 0 && charCode <= 128)
                realLength += 1;
            else
                realLength += 2;
        }
        return realLength;
    }
    
    <asp:TextBox ID="txtOwner_Name" runat="server" Width="200px" BackColor="LightYellow"
                            onkeyup="textLimitCheckSj(this,50,'spOwner_Name')"></asp:TextBox><span id="spOwner_Name"
                                style="color: #808080"><em>(50字以内)</em></span>
    

     

  • 相关阅读:
    单词接龙
    洛谷 P1015 回文数
    洛谷 P1012 拼数
    codevs 2780 ZZWYYQWZHZ
    专项练习之字符串
    模拟题1
    专项训练之线段树
    复习题之求后序遍历
    复习题之二叉树的遍历
    Hdu 3037 Saving Beans(Lucus定理+乘法逆元)
  • 原文地址:https://www.cnblogs.com/52net/p/3380398.html
Copyright © 2011-2022 走看看