String.prototype.byteLen = function(){
var len = 0,
i = this.length;
while(i--)
{
  len += (this.charCodeAt(i)>255 ? 2 : 1);
}
  return len;
};

  ("测试").byteLen(); //会返回4

  ("aaa").byteLen(); //会返回3

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2021-07-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案