方法1: 复制代码 代码如下: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; } } } return bytesCount; } 方法2: 复制代码 代码如下:function getBytesCount2(str) { if (str == null) { return 0; } else { return (str.length + str.replace(/[u0000-u00ff]/g, "").length); } }
推荐阅读
javascript css在IE和Firefox中区别分析
一、document.formName.item("itemName") 问题 问题说明:IE下,可以使用 document.formName.item("itemName") 或 document.formName.elements ["elementName"];Firefox下,只能使用document.formName.elemen>>>详细阅读
本文标题:js获取提交的字符串的字节数
地址:http://www.17bianji.com/kaifa2/JS/28976.html
1/2 1