以下是我正在使用的代码。
JS
const clockContainer = document.querySelector('.js-clock'),
clockTitle = clockContainer.querySelector('h1');
function getTime() {
const date = new Date();
const minutes = date.getMinutes();
const hours = date.getHours();
const seconds = date.getSeconds();
clockTitle.innerText = `${hours}:${minutes}:${seconds}`;
}
function init() {
getTime();
}
init();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>clock</title>
</head>
<body>
<div class="js-clock">
<h1>00:00</h1>
</div>
<script src="clock.js"></script>
</body>
</html>
为什么这段代码在CodeSandbox中不能运行,但是在vscode中可以?
我不知道为什么... 我尝试了几乎所有的方法,但是这段代码在CodeSandbox中无法运行。