欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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:
復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評(píng)論