簡體   English   中英

使用jQuery刪除HTML內的樣式標簽

[英]remove style tag inside html using jquery

我如何刪除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

我的風格代碼

您可以使用jQuery .remove()方法從頁面中刪除所有樣式標簽:

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

如果HTML在變量( html )中,請使用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM