Javascript js如何在getComputedStyle规则中获取源css规则

Javascript js如何在getComputedStyle规则中获取源css规则,javascript,styles,rules,getcomputedstyle,Javascript,Styles,Rules,Getcomputedstyle,正如我们所知,通过window.getComputedStyle()方法,我们可以获得特定元素的计算样式。(见附件)。 我的问题是,我们如何知道计算样式中的CSSStyleDeclaration来自何处。例如,在中,我定义了如下css规则: #element{ color:red; border:1px solid #999; margin:10px; } 如果我使用getComputedStyle(element,null).getPropertyValue(“color”)它返

正如我们所知,通过window.getComputedStyle()方法,我们可以获得特定元素的计算样式。(见附件)。 我的问题是,我们如何知道计算样式中的CSSStyleDeclaration来自何处。例如,在中,我定义了如下css规则:

#element{
  color:red;
  border:1px solid #999;
  margin:10px;
}
如果我使用getComputedStyle(element,null).getPropertyValue(“color”)它返回“rgb(255,0,0)”,但是我怎么知道属性“color”是在css选择器“#element”中定义的呢


谢谢

@Tsingbo,据我所知这是不可能的,但你可以在Chrome中尝试window.getmatchedcsrules。

@Tsingbo,据我所知这是不可能的,但你可以在Chrome中尝试window.getmatchedcsrules。

出于好奇,你为什么需要这样做?除了解析CSS文件,我认为没有其他方法。因为我想更新CSS规则,所以我需要知道要更改哪个CSSStyleDeclaration。出于好奇,为什么需要更改?我认为除了解析CSS文件之外没有其他方法。因为我想更新CSS规则,所以我需要知道要更改哪个CSSStyleDeclaration。