删除html标签或标签属性以及样式

JavaScript module for stripping HTML tags and/or HTML element attributes from strings.

安装

npm install js-striphtml

使用

var striphtml = require('js-striphtml');
striphtml.striptags('<body>I am a <b>HTML</b> string.<div class="clear"></div></body>', [ 'b' ]);
// Returns "I am a <b>HTML</b> string."
var striphtml = require('js-striphtml');
striphtml.stripAttr('<p style="background:green">I am a <b>HTML</b> string. <img src="stringimg.jpg" align="right" /></p>', { 'img': [ 'src' ] } );
// Returns "<p>I am a <b>HTML</b> string. <img src="stringimg.jpg" /></p>"
posted @ 2020-05-16 17:50  热爱前端知识  阅读(819)  评论(0编辑  收藏  举报