String.prototype.trim=function(){
return this.replace(/(^\s+)|(\s+$)/g,'');
}
低版本浏览器没trim方法。用正则兼容。
// ^ 表示以...开头
// | 或者
// $ 表示以...结尾
// /s 表示空白字符
// * 表示一个或多个
// \^/s*\ 表示。以 空白字符开头的一个或多个空白字符
String.prototype.trim=function(){
return this.replace(/(^\s+)|(\s+$)/g,'');
}
低版本浏览器没trim方法。用正则兼容。
// ^ 表示以...开头
// | 或者
// $ 表示以...结尾
// /s 表示空白字符
// * 表示一个或多个
// \^/s*\ 表示。以 空白字符开头的一个或多个空白字符