您是第 Web Page Tracking 位访客

水~墨~

昂首阔步,不留一点遗憾!

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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>

posted on 2014-03-20 00:11  水墨.MR.H  阅读(303)  评论(0编辑  收藏  举报
知识共享许可协议
本博客为水墨原创,基于Creative Commons Attribution 2.5 China Mainland License发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的水墨(包含链接)。如您有任何疑问或者授权方面的协商,请给我留言。