搜索内容高亮显示

var str = "aaa的大收拾收拾的大收拾收拾得到的淡淡的洒事实上";
        var sub = '的';
        var rep = 'new';
        var newStr;
        var reg = new RegExp(sub,"g");
        console.log(str.replace(reg,rep))
        function getNewStr(originStr,subStr,replacement){
            newStr = originStr.replace(subStr,replacement);
            if(newStr.match(subStr)){
                getNewStr(newStr,subStr,replacement);
            }
            console.log(14)
            return newStr
        }
        var objStr = getNewStr(str,sub,rep);
        console.log(objStr)

posted @ 2017-02-21 11:34  凉城丶旧梦  阅读(283)  评论(0编辑  收藏  举报