function(str)
{
var realLength = 0;
for (var i = 0; i < str.length; i++)
{
charCode = str.charCodeAt(i);
if (charCode >= 0 && charCode <= 128)
realLength += 1;
else
realLength += 2;
}
return realLength;
}
JS计算字符串长度(汉字算作两个字符)
最新推荐文章于 2023-05-03 11:46:08 发布