简体   繁体   English

Firefox:样式表在开发者工具中出现多次

[英]Firefox: style sheet appears multiple times in developer tools

I have a few linked style sheets on a sample site ( https://responsive.webcraft101.com/index.html ).我在示例站点上有一些链接样式表( https://responsive.webcraft101.com/index.html )。 One of the links is to be toggled on and off, so it includes an id :其中一个链接将被打开和关闭,因此它包含一个id

<link id="sketch" rel="stylesheet" type="text/css" href="styles/sketch.css">

I jave some JavaScript on the header element which disables and enables the style sheet.我在 header 元素上添加了一些header元素,该元素禁用和启用样式表。 A simplified version is:一个简化的版本是:

var ss = document.querySelector('link#sketch');
var header = document.querySelector('header');
header.onclick = event => { ss.disabled = !ss.disabled; } ;

It works well enough.它工作得很好。 However, when I look at the style sheets in Firefox's developer tools, the sketch.css style sheet is added to the list every time disabled is set to false .但是,当我查看 Firefox 开发人员工具中的样式表时,每次disabled设置为false时, sketch.css样式表都会添加到列表中。

Does that indicate something wrong with the process?这是否表明该过程有问题? How can I stop this from happening?我怎样才能阻止这种情况发生?

I can see it happening in firefox but not brave .我可以看到它发生在firefox但不勇敢 I am not sure if it actually has that many copies or whether it's just showing a log of as they were applied.我不确定它是否真的有那么多副本,或者它是否只是显示应用它们的日志。 Personally, I wouldn't do it this way.就个人而言,我不会这样做。 I think that you can do it by having one class in the body that you toggle.我认为您可以通过在您切换的主体中安装一个 class 来做到这一点。 I don`t think this was an intended design parameter.我不认为这是一个预期的设计参数。 It is not a visual element.它不是视觉元素。

I have only seen this used as a way to lazy load the style sheet.我只看到这被用作延迟加载样式表的一种方式。 And then they add a link instead of enabling it.然后他们添加一个链接而不是启用它。

Usage Example here 这里的用法示例

This is obviously a bug in the Style Editor.这显然是样式编辑器中的一个错误。 And it looks like it is going to be fixed in an upcoming Firefox version .看起来它将在即将发布的 Firefox 版本中修复

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

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