📜  js 多字节字符串长度 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:23.245000             🧑  作者: Mango

代码示例1
function lengthInPageEncoding(s) {
  var a = document.createElement('A');
  a.href = '#' + s;
  var sEncoded = a.href;
  sEncoded = sEncoded.substring(sEncoded.indexOf('#') + 1);
  var m = sEncoded.match(/%[0-9a-f]{2}/g);
  return sEncoded.length - (m ? m.length * 2 : 0);
}