JS计算字符串字节数

function getByteLen(str) {
    var l = str.length;
    var n = l;
    for (var i = 0; i < l; i++)
        if (str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255)
        n++;
    return n
}

原文地址:https://www.cnblogs.com/myssh/p/1694869.html