您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

js获取提交的字符串的字节数代码示例

2025/10/1 14:36:33发布15次查看
js计算字符串的字节数的代码
方法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); } }
以上就是js获取提交的字符串的字节数代码示例的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product