删除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>"

猜你喜欢

转载自www.cnblogs.com/10manongit/p/12901488.html
今日推荐