去处HTML标签

JavaScript去处HTML标签

       function removeHTMLTag(str) {
            str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
            str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
            str = str.replace(/\n[\s| | ]*\r/g, '\n'); //去除多余空行
            str = str.replace(/&nbsp;/ig, '');//去掉&nbsp;
            str = str.replace(/&lt;/ig, '');
            str = str.replace(/&gt;/ig, '');
            str = str.replace(/[div|\/div]/g, '');
            str = str.replace(/&lt;[ -~]*&gt;/ig, '');//去掉替换后的<>标签
            return str;
        }

 

posted @ 2016-01-26 11:17  北极熊爱吃鱼  阅读(264)  评论(0编辑  收藏  举报