js字符串两边截取空白的trim的原型方法的实现
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/g,'');
}
例子:
var test = " abc ";
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/g,'');
}
test = test.trim();
console.log(test);