拓展javascript内置函数
1、获取字符串字节数
//获取字符串字节数 //方法一 /* */ String.prototype.getBytesLength = function () { var length = 0; for (i = 0; i < this.length; i++) { iCode = this.charCodeAt(i); if ((iCode >= 0 && iCode <= 255) || (iCode >= 0xff61 && iCode <= 0xff9f)) { length += 1; } else { length += 2; } } return length; } //方法二 /* */ String.prototype.getBytesLength = function () { return this.replace(/[^\x00-\xff]/gi, "--").length; } document.write("Sn杨".getBytesLength());//结果:4
"唯有高屋建瓴,方可水到渠成"