jquery 判断字符串长度

 function titleLength(str) {
        var strLength = 0;
        var list = str.split("");
        for (var i = 0; i < list.length; i++) {
            if (str.charCodeAt(i) > 0 && str.charCodeAt(i) < 128)
                strLength = strLength + 0.5;
            else
                strLength = strLength + 1;
        }
        return strLength;
    }

 

posted @ 2020-04-17 16:11  双木君  Views(5704)  Comments(0Edit  收藏  举报