码迷,mamicode.com
首页 > Web开发 > 详细

js 字符串扩展

时间:2014-08-04 13:28:17      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   io   art   cti   ar   

 

<script type="text/javascript" language="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,"");
   }
 
</script>

<script type="text/javascript" language="JavaScript">
    function test() {
        var a = "abcdef".startWith("abc");
        alert("a : " + a);
        var b = "abcdef".endWith("def");
        alert("b : " + b);
    }

    String.prototype.endWith = function(str) {
        if (str == null || str == "" || this.length == 0
                || str.length > this.length)
            return false;
        if (this.substring(this.length - str.length) == str)
            return true;
        else
            return false;
        return true;
    }

    String.prototype.startWith = function(str) {
        if (str == null || str == "" || this.length == 0
                || str.length > this.length)
            return false;
        if (this.substr(0, str.length) == str)
            return true;
        else
            return false;
        return true;
    }
</script>

 

js 字符串扩展,布布扣,bubuko.com

js 字符串扩展

标签:style   blog   color   java   io   art   cti   ar   

原文地址:http://www.cnblogs.com/mjorcen/p/3889597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!