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);
js字符串两边截取空白的trim的原型方法的实现
原文地址:http://www.cnblogs.com/wongh/p/7670155.html