어떻게 문자 개 수 를 통계 합 니까?

https://jsfiddle.net/k5q0ue7y/



    
    <script type="text/javascript">
 
        var maxstrlen = 160;
        function Q(s) { return document.getElementById(s); }
 
        function checkWord(c) {
            len = maxstrlen;
            var str = c.value;
            myLen = getStrleng(str);
            var wck = Q("wordCheck");
 
            if (myLen > len * 2) {
                c.value = str.substring(0, i + 1);
            }
            else {
                wck.innerHTML = Math.floor((len * 2 - myLen) / 2);
            }
        }
 
        function getStrleng(str) {
            myLen = 0;
            i = 0;
            for (; (i < str.length) && (myLen <= maxstrlen * 2); i++) {
                if (str.charCodeAt(i) > 0 && str.charCodeAt(i) < 128)
                    myLen++;
                else
                    myLen += 2;
            }
            return myLen;
        }
    
    </script>


    <form id="form1" runat="server">
    <div style="font-size: 16px">
                 ,        ,      ;<br/>
                   ,             。
    </div>
    <div>
        <textarea onkeyup="javascript:checkWord(this);" onmousedown="javascript:checkWord(this);" name="content" style="overflow-y: scroll"/>
    </div>
    <div>
             <span style="font-family: Georgia; font-size: 26px;" id="wordCheck">160</span>   
    </div>
    </form>


</code></pre> 
 </div> 
</div>
                            </div>
                        </div>

좋은 웹페이지 즐겨찾기