如何在javascript实现VBS中LenB("abc一二三")等于12这样的功能

解决方案 »

  1.   

    如何在javascript实现VBS中LenB("abc一二三")等于12这样的功能
      

  2.   

    "abc一二三".replace(/[^\x00-\xff]/g,"**").length;
      

  3.   

    <script language="JavaScript">
    <!--
    var str='测试一下asdfghh';
    String.prototype.binaryLength=function (){
    var strLen=this.length;
    var binLen=0;
    for(var iCnt=0;iCnt<strLen;iCnt++){
    binLen++;
    if(this.charCodeAt(iCnt)>128) binLen++;
    }
    return binLen;
    }
    alert(str.binaryLength());
    -->
    </script>