<script language="javascript">
var xxx = "我";
String.prototype.lenb = function() {
return this.replace(/[^\x00-\xff]/g,"**").length;
}
alert(xxx.lenb());
</script>
var xxx = "我";
String.prototype.lenb = function() {
return this.replace(/[^\x00-\xff]/g,"**").length;
}
alert(xxx.lenb());
</script>
所以mbx615是行的
也可以
<SCRIPT LANGUAGE="JavaScript">
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;
}
}
}
alert(bytesCount);
}
getBytesCount("aa我")
</SCRIPT>