javascript常用方法函数收集
字符串长度截取 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 function cutstr(str, len) { var temp, icount = 0, patrn = /[^\x00-\xff]/,strre = "" ; for ( var i = 0; i < str.length; i++) { if (icount < len - 1) { temp = str.substr(i, 1); if (patrn.exec(temp) == null ) { icount = icount + 1 } else { icount = icount + 2 } strre += temp } else { break ; } } return strre + "..." } 替换全部 1 2 3 String.prototype.replaceAll = function (s1, s2) { return this .replace( new RegExp(s1, "gm" ), s2) } 清除空格 1 2 3 4 String.prototype.trim = function () { var reExtraSpace = /^\s*(.*?)\s+$/; return this .replace