类方法
//去除左右空格
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}
//去除左空格
String.prototype.ltrim=function(){
return this.replace(/(^\s*)/g,"");
}
//去除右空格
String.prototype.rtrim=function(){
return this.replace(/(\s*$)/g,"");
}
函数
function trim(str){ //删除左右两端的空格
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str){ //删除左边的空格
return str.replace(/(^\s*)/g,"");
}
function rtrim(str){ //删除右边的空格
return str.replace(/(\s*$)/g,"");
}