如何删除html中的样式标签
我想删除其中的完整样式标签和 css 我试试这个:
html = html.replace(/<br>/g, ' ');
console.log('0='+html);
html2 = html.replace(/<div>/g, ' ');
console.log('1='+html2);
html2 = html2.replace(/ /g, ' ');
html2 = html2.replace(/(<([^>]+)>)/ig,"");
但这只是删除了样式标签,并没有删除 css
最佳答案
您可以使用 jQuery .remove()
方法从您的页面中删除任何样式标签:
$('html').find('style').remove();
如果 HTML 位于变量 (html) 中,请使用:
$('style', html).remove();
关于javascript - 使用 jquery 删除 html 中的样式标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25226505/