Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何仅获取样式表中声明的样式';s声明,而不是计算的声明?_Javascript_Html_Css - Fatal编程技术网

Javascript 如何仅获取样式表中声明的样式';s声明,而不是计算的声明?

Javascript 如何仅获取样式表中声明的样式';s声明,而不是计算的声明?,javascript,html,css,Javascript,Html,Css,如果我在document.styleSheets中循环查找与.myClass匹配的css规则,我会得到比实际声明的样式值更多的样式值 例如,使用此CSS: .myClass { border: none; } 我会得到所有这些规则: border: medium none borderBottom: medium none borderBottomColor: -moz-use-text-color MozBorderBottomColors: none borderBottomStyle:

如果我在
document.styleSheets
中循环查找与
.myClass
匹配的css规则,我会得到比实际声明的样式值更多的样式值

例如,使用此CSS:

.myClass { border: none; }
我会得到所有这些规则:

border: medium none
borderBottom: medium none
borderBottomColor: -moz-use-text-color
MozBorderBottomColors: none
borderBottomStyle: none
borderBottomWidth: medium
borderColor: -moz-use-text-color
borderImage: none
borderImageSource: none
borderImageSlice: 100% 100% 100% 100%
borderImageWidth: 1 1 1 1
borderImageOutset: 0 0 0 0
borderImageRepeat: stretch stretch
borderLeft: medium none
borderLeftColor: -moz-use-text-color
MozBorderLeftColors: none
borderLeftStyle: none
borderLeftWidth: medium
borderRight: medium none
borderRightColor: -moz-use-text-color
MozBorderRightColors: none
borderRightStyle: none
borderRightWidth: medium
borderStyle: none
borderTop: medium none
borderTopColor: -moz-use-text-color
MozBorderTopColors: none
borderTopStyle: none
borderTopWidth: medium
borderWidth: medium
color: rgb(200, 200, 200)
MozBorderImage: none

如何在样式表中只找到我实际设置的规则?

您的问题再模糊不过了。你可以发布一些代码或者详细说明一下吗?这是规定。cssText@dandavis他可能在寻找那个的解析版本。。。或者至少是一个使声明折叠的解析版本。@Bart:对,必须在cssText上使用解析器来查找不带缩写和继承的属性。甚至一个幼稚的regexp也可能suffice@dandavis谢谢你,看来会有用的。你能把这个作为答案吗?