js 去空格!
方法1
/** trim() method for String */
String.prototype.trim=function() {
return this.replace(/(^\s*)|(\s*$)/g,'');
};
方法2
//去左空格;
function ltrim(s){
return s.replace(/(^\s*)/, "");
}
//去右空格;
function rtrim(s){
return s.replace(/(\s*$)/, "");
}
//去左右空格;
function trim(s){
//s.replace(/(^\s*)|(\s*$)/, "");
return rtrim(ltrim(s));
}