1.扩展string类型,添加一个trim方法取出字符串两边空白
原理:prototype属性
<script type="text/javascript">
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,"");
}
var a = "sdf";
a.trim();
</script>
昂首阔步,不留一点遗憾