使用javascript过滤html的字符串(注释标记法)


function DeleteHtmlFromStartToEnd(str, begin, end) {
            str = str.replace(begin + end, "");
            if (str.indexOf(begin) == -1) {//没找到
                return str;
            }
            var substr = str.substring(str.indexOf(begin) + begin.length, str.indexOf(end));
            str = str.replace(substr, "");
            return DeleteHtmlFromStartToEnd(str, begin, end);
        }
        var str = '00000<!--deleteBegin-->1234567<!--deleteEnd-->111111<!--deleteBegin-->890<!--deleteEnd-->22222<!--deleteBegin-->890<!--deleteEnd--><!--deleteBegin-->890<!--deleteEnd-->3';
        var result = DeleteHtmlFromStartToEnd(str, '<!--deleteBegin-->', '<!--deleteEnd-->');
        alert(result);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdgzyd.html