正则去除html字符串中的注释、标签、属性


var str = '<!-- 注释1 --><h1 style="color:#00ff00;text-align: center;">ProsperLee<!-- 注释 --></h1>';
        document.write(str.replace(/<!--[\w\W\r\n]*?-->/gmi, '')); // 去除HTML中的注释
        document.write(str.replace(/<[^>]+>/g,"")); // 去除HTML标签
        document.write(str.replace(/(<[^\s\/>]+)\b[^>]*>/gi,"$1>")); // 去除HTML标签中的属性

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM