javascript - ReferenceError: document is not defined exited with code=1 in 0.107 seconds
问题描述
对不起,如果这是一个新手问题,我刚开始编写 html、css 和 javascript 并遇到了这个错误-
ReferenceError:文档未定义**->此问题仅在vscode中,当我在google控制台上运行同一行时它可以工作,现在我的问题是我调用了函数增加,当我在网站上单击INCREMENT时它应该像0,1,2,3
```
count = 0;
let constEl = document.getElementById("coun");
function increase() {
count += 1;
console.log("CLICKED!");
constEl.textContent = count;
console.log(constEl);
}
```
~~~<!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" />
<title>People Counter</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>People entered:</h1>
<h2 id="coun">0</h2>
<button id="add_btn" onclick="increase">INCREMENT</button>
<button id="save_btn">Save</button>
<script src="counter.js"></script>
</body>
</html>~~~
body {
margin: 0;
border: 0;
background-image: url("station.jpg");
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
font-weight: bolder;
background-size: cover;
text-align: center;
}
h1 {
margin-top: 10px;
margin-bottom: 10px;
text-align: center;
font-size: 3rem;
}
#counter_el {
text-align: center;
text-transform: capitalize;
font-size: 4rem;
margin: 0;
border: 0ch;
}
button {
size: 2px;
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
}
#add_btn:hover {
background-color: limegreen;
color: white;
}
#add_btn {
border: 2px solid limegreen;
color: black;
transition-duration: 0.4s;
border-radius: 2px;
}
#save_btn {
border: 2px solid red;
transition-duration: 0.4s;
border-radius: 2px;
}
#save_btn:hover {
background-color: red;
color: white;
}```
解决方案
推荐阅读
- python-3.x - 根据任何属性中的关键字过滤掉与美丽汤一起发现的元素
- java - JAXB2:带有两个包的 JaxBContext
- jenkins - 如果任何测试用例使用 findText 插件失败,如何使 jenkins 构建失败
- delphi - Delphi + Binance Api + 限价单问题 签名无效
- python - 处理 Pandas 列的更快方法
- javers - 从 javers Change 类中仅检索 left、right、propertyName
- c# - 如何创建将在 Linux Debian - ASP.NET 上运行的 ASP.NET 项目?
- mysql - 如何在 laravel 中使用它们各自的值更新多个列?
- c# - 测量工作室图表,集合被修改异常
- typescript - 如何在构造函数的重载函数中使用子类中的字段值