<p>//清除两边的空格String.prototype.trim=function(){returnthis.replace(/(^s*)|(s*$)/g,'');};//保留数字String.prototype.GetNum=function(){varregEx=/[^d]/g;returnthis.replace(regEx,'');};//日期相差天数Date.prototype.diff=function(date){returnMath.ceil((this-date)/(1000*60*60*24));}字符串包含字符串判断String.prototype.contains=function(sub){returnthis.indexOf(sub)!=-1;}//检测是否为空Object.prototype.IsNullOrEmpty=function(){varobj=this;varflag=false;if(obj==null||obj==undefined||typeof(obj)=='undefined'||obj==''){flag=true;}elseif(typeof(obj)=='string'){obj=obj.trim();if(obj==''){//为空flag=true;}else{//不为空obj=obj.toUpperCase();if(obj=='NULL'||obj=='UNDEFINED'||obj=='{}'){flag=true;}}}else{flag=false;}returnflag;};*字符串比较大小**/String.prototype.compare=function(b){if(!b)return-1;if(this.length!=b.length)returnthis.length-b.length;vari=0;for(;i<this.length;i++){varval=this.charCodeAt(i)-b.charCodeAt(i);if(val!=0)returnval;}return0;}//格式化字符串String.Format=function(){if(arguments.length==0){return'';}if(arguments.length==1){returnarguments[0];}varreg=/{(d+)?}/g;varargs=arguments;varresult=arguments[0].replace(reg,function($0,$1){returnargs[parseInt($1)+1];});returnresult;};此文由起航劳务派遣系统编辑所撰。</p>