计算文本框的输入字符数的简易方法:

var text = document.getElementsByTagName('textarea')[0];
var tValue = text.value;
num = Math.ceil(getLength(tValue)/2);

//正则:用于区分中文为两个字节
function getLength(str){
    return String(str).replace(/[^\x00-\xff]/g,'aa').length;
}

将一个中文字符替换成2个英文字符,对替换后的字符串进行统计

相关文章:

  • 2021-12-02
  • 2021-12-02
  • 2021-09-21
  • 2022-01-13
  • 2021-09-23
  • 2022-01-25
  • 2021-12-02
猜你喜欢
  • 2021-11-10
  • 2022-01-03
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案