javascript - 使用 jquery 删除 html 中的样式标签

标签 javascript jquery html css styles

如何删除html中的样式标签

我想删除其中的完整样式标签和 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,"");

但这只是删除了样式标签,并没有删除 css

my style code

最佳答案

您可以使用 jQuery .remove() 方法从您的页面中删除任何样式标签:

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

如果 HTML 位于变量 (html) 中,请使用:

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

关于javascript - 使用 jquery 删除 html 中的样式标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25226505/

相关文章:

javascript - 如何跳过构建工作区的文件夹的eclipse验证(Luna版)

javascript - 为什么这不起作用?

jquery - 防止某些元素渲染 Canvas

jquery - 引用错误 : Can't find variable: jQuery

html - 如何在HTML页面中获取EPSON TM-T88V小票打印机的默认字体 "Font A11"?

javascript - 手动向输入元素添加字符时出现光标问题

javascript - 使用 jQuery 拖放防止点击事件

javascript - 是什么导致了 "Unchecked runtime.lastError: The message port closed before a response was received."警告?

javascript - 水平滚动图像缩略图并在鼠标悬停时弹出图像

html - CSS 自定义标签形状 - 额外的行