我在使用JavaScript读取页面元素css属性时,发现控制台中打印的属性值为空。如何将正确的属性值呈现在控制台中?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.my_box{
width: 250px;
height: 250px;
background-color: cornflowerblue;
}
</style>
<title>Document</title>
</head>
<body>
<div class="my_box"></div>
</body>
<script>
var one = document.querySelector(".my_box");
var box_width = one.style['width'];
var box_height = one.style['height'];
console.log(box_width);
console.log(box_height);
</script>
</html>