Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.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/7/symfony/6.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中的css属性_Javascript_Css - Fatal编程技术网

在页面加载时获取javascript中的css属性

在页面加载时获取javascript中的css属性,javascript,css,Javascript,Css,我试图在页面加载时获得css属性,但正如您在下面看到的,它不会显示显示,但如果我更改它,它会正确显示。我的问题是如何在显示器1上显示“块” 谢谢你的帮助 let hello=document.getElementById('hello'); document.getElementById('you').innerHTML+=hello.style.display; hello.style.display=“内联块”; document.getElementById('too').innerHT

我试图在页面加载时获得css属性,但正如您在下面看到的,它不会显示显示,但如果我更改它,它会正确显示。我的问题是如何在显示器1上显示“块”

谢谢你的帮助

let hello=document.getElementById('hello');
document.getElementById('you').innerHTML+=hello.style.display;
hello.style.display=“内联块”;
document.getElementById('too').innerHTML+=hello.style.display
你好{ 背景颜色:黄色; 高度:20px; 显示:块; } 你好 显示1:
显示2:
.style
读取元素的内联样式(如
中所示),而不是样式表。可以使用
hello.getBoundingClientRect().height
读取DOM元素的高度

或者,您可以使用
getComputedStyle

const styles=window.getComputedStyle(您好)
const height=styles.getPropertyValue('height'))

.style
读取元素的内联样式(如在
中),而不是样式表。可以使用
hello.getBoundingClientRect().height
读取DOM元素的高度

或者,您可以使用
getComputedStyle

const styles=window.getComputedStyle(您好)
const height=styles.getPropertyValue('height'))

我需要获取显示值,而你的getBoundingClientRect()不适用,因此我编辑了我的帖子getComputedStyle就是我需要的,谢谢:)我需要获取显示值,而你的getBoundingClientRect()不适用,所以我编辑了我的帖子getComputedStyle就是我需要的,谢谢:)