为String扩展trim方法

String.prototype.trim = function(){

//return this.replace(/(^\s*)|(\s*$)/g, "");
//去 与' '空格
return this.replace(/(^\s*)|(\s*$)/g, "").replace(/(^( )*)|(( )*$)/g, "");
}

使用JQuery提供的trim()方法

$.trim(str);

相关文章: