亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js獲取提交的字符串的字節(jié)數(shù)

 更新時間:2009年02月09日 14:55:44   作者:  
js計算字符串的字節(jié)數(shù)的代碼
方法1: 
復制代碼 代碼如下:

function getBytesCount(str)
{
var bytesCount = 0;
if (str != null)
{
for (var i = 0; i < str.length; i++)
{
var c = str.charAt(i);
if (/^[\u0000-\u00ff]$/.test(c))
{
bytesCount += 1;
}
else
{
bytesCount += 2;
}
}
}
return bytesCount;
}

方法2:
復制代碼 代碼如下:

function getBytesCount2(str)
{
if (str == null)
{
return 0;
}
else
{
return (str.length + str.replace(/[\u0000-\u00ff]/g, "").length);
}
}

相關(guān)文章

最新評論