简体   繁体   English

使用jQuery删除HTML内的样式标签

[英]remove style tag inside html using jquery

how can i remove style tag inside html 我如何删除html内的样式标签

i want remove complete style tag and css inside it i try this: 我想删除其中的完整样式标签和CSS,请尝试以下操作:

  html = html.replace(/<br>/g, ' ');
        console.log('0='+html);
        html2 = html.replace(/<div>/g, ' ');
        console.log('1='+html2);
        html2 = html2.replace(/&nbsp;/g, ' ');
        html2 = html2.replace(/(<([^>]+)>)/ig,"");

but this just remove style tag and don't remove css 但这只是删除样式标签,而不删除CSS

我的风格代码

You can use the jQuery .remove() method to remove any style tags from your page : 您可以使用jQuery .remove()方法从页面中删除所有样式标签:

$('html').find('style').remove();

If the HTML is in a variable ( html ), use: 如果HTML在变量( html )中,请使用:

$('style', html).remove();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM