4

我想显示一个没有应用任何 CSS 的页面。是否可以在页面内添加一个 jquery 开关以禁用所有样式表?

原因:我想向客户展示设计的重要性,让他有机会禁用他网站的 css 样式。当他可以自己触发时,这更有说服力:)

4

8 回答 8

6

如果您希望它在单击后触发:

$(".element").click(function(){
    $("link[rel='stylesheet']").remove();
});

或在开头:

 $(document).ready(function(){
        $("link[rel='stylesheet']").remove();
 });
于 2013-01-31T15:50:16.043 回答
4

试试这个:

$('link[rel="stylesheet"]').remove();

这将从页面中删除所有样式表(所有样式都适用于这些样式表)。

于 2013-01-31T15:47:06.773 回答
2

只花了几分钟起草一份

 (function(f,a,s,x){
  x=$(a);x.map(function(i,o){o=$(o);o.data(s+s,o.attr(s));o.removeAttr(s)});
  $(s+',link[rel='+s+'sheet]').appendTo(f);
  setTimeout(function(){
   $(a,f).appendTo('head');
   x.map(function(i,o){o=$(o);o.attr(s,o.data(s+s))})
  },999);
 })($('<i>'),'*','style');
于 2013-01-31T15:54:39.930 回答
1

禁用所有

StyleSheetList.prototype.forEach=Array.prototype.forEach; // *Note
document.styleSheets.forEach((ss)=>ss.disabled=true);

或(全部禁用)

for(styleSheet of document.styleSheets){ styleSheet.disabled=true; }

或(全部删除)

StyleSheetList.prototype.forEach=Array.prototype.forEach;
document.styleSheets.forEach((ss)=>ss.ownerNode.parentNode.removeChild(ss.ownerNode));

或(全部删除)

for(styleSheet of document.styleSheets){ styleSheet.ownerNode.parentNode.removeChild(styleSheet.ownerNode); }

*注意:如果你不想改变原型,你可以这样调用它:

Array.prototype.forEach.apply(document.styleSheets,[(ss)=>ss.disabled=true])
于 2019-11-30T16:17:09.050 回答
0

试试这个

$('link[rel="stylesheet"]').remove();
于 2013-01-31T15:52:13.380 回答
0

把它放在准备好的文件上:

$('link[rel=stylesheet]').remove();

或将其绑定到按钮。

于 2013-01-31T15:56:19.860 回答
0

一种粗暴、肮脏和粗暴的方法:

document.querySelector("head").remove();

可以粘贴为书签 URL 的相同代码的书签版本。

您也可以将其粘贴到地址栏中(出于安全原因,当您粘贴文本时,chrome/firefox 会删除javascript:开头的位,因此您需要手动输入):

javascript:(function(){document.querySelector("head").remove();})()
于 2017-03-09T16:23:22.300 回答
0

使用下面的代码删除各种样式,内联、内部、外部。

let elements=document.querySelectorAll("*");
elements.forEach(el=>{
    if(el.tagName==="LINK" || el.tagName==="STYLE") el.remove();
    else el.removeAttribute("style");
});

晚点再谢我!;)

于 2021-05-02T12:35:42.187 回答