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

JS中自定义replace可替换特殊符号$等,但无法忽略大小写的函数

时间:2016-10-07 18:08:14      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:

//可替换特殊符号$等,但无法忽略大小写的函数
String.prototype.replaceStr = function (s1, s2) {
    this.str = this;
    if (s1.length == 0) return this.str;
    var idx = this.str.indexOf(s1);
    while (idx > -1) {
        this.str = this.str.substring(0, idx) + s2 + this.str.substr(idx + s1.length);
        idx = this.str.indexOf(s1);
    }
    return this.str;
}

  

JS中自定义replace可替换特殊符号$等,但无法忽略大小写的函数

标签:

原文地址:http://www.cnblogs.com/waw/p/5936300.html

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