【发布时间】:2022-06-23 18:37:27
【问题描述】:
我是 Javascript 新手,我不知道为什么会出现此错误。 这是我的代码:
const bckg = document.querySelector(".bckg");
const compStyle = getComputedStyle(bckg);
body {
box-sizing: content-box;
position: relative;
}
.visible {
position: relative;
top: 50px;
margin: auto;
background-color: bisque;
height: 300px;
width: 600px;
overflow: hidden;
}
.bckg {
position: absolute;
left: 0px;
width: 1200px;
height: 300px;
background-image: url("bckg.jpg")
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script src="script.js"></script>
<div class="visible">
<div class="bckg" id="bckg">
<div class="player"></div>
<div class="obstacle"></div>
</div>
</div>
</body>
</html>
我在 Mozilla 中遇到的这个错误:“未捕获的 TypeError: Window.getComputedStyle: Argument 1 is not an object。” 会是什么?
【问题讨论】:
-
你知道这是一个javascript相关的问题,但仍然没有提供任何javascript代码
-
这能回答你的问题吗? Change label text using JavaScript
标签: javascript html css queryselector getcomputedstyle