javascript常用方法函数收集
字符串长度截取 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 + "..." } 替换全部 String . prototype . replaceAll = function ( s1 , s2 ) { return this . replace ( new RegExp ( s1 , "gm" ), s2 ) } 清除空格 String . prototype . trim = function () { var reExtraSpace = /^\s*(.*?)\s+$/ ; return this . replace ( reExtraSpace , "$1" )