js

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>

原文地址:https://www.cnblogs.com/StudyLife/p/3612679.html