<script language="javascript">
var xxx = "我";
String.prototype.lenb = function() {
  return this.replace(/[^\x00-\xff]/g,"**").length;
}
alert(xxx.lenb());
</script>

解决方案 »

  1.   

    字节数就是要区分出汉字占两个。
    所以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>