Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.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 无法使用js检索样式_Javascript_Css_Dhtml - Fatal编程技术网

Javascript 无法使用js检索样式

Javascript 无法使用js检索样式,javascript,css,dhtml,Javascript,Css,Dhtml,我检索到的只是一个空框。要获得计算样式,您必须走一条不同的路线,如下所示: <html> <head> <style> #menu{ color :red; } </style> </head> <body> <div id="menu"> ABCXTZ </div> </body> <script> a = document.getElementById('menu'); a

我检索到的只是一个空框。

要获得计算样式,您必须走一条不同的路线,如下所示:

<html>
<head>
<style>
#menu{
color :red;
}
</style>
</head>
<body>
<div id="menu">
ABCXTZ
</div>
</body>
<script>
a = document.getElementById('menu');
alert(a.style.color);
</script>
</html
,获取在元素本身上定义的属性,而不是从它匹配的规则继承的属性。上面使用了如果可用的,并且在IE的情况下,返回到。

要获得计算样式,您必须走一条不同的路线,如下所示:

<html>
<head>
<style>
#menu{
color :red;
}
</style>
</head>
<body>
<div id="menu">
ABCXTZ
</div>
</body>
<script>
a = document.getElementById('menu');
alert(a.style.color);
</script>
</html
,获取在元素本身上定义的属性,而不是从它匹配的规则继承的属性。如果可用,上面使用了,在IE的情况下,返回到