【发布时间】:2023-01-15 00:45:57
【问题描述】:
But_1 正在工作,但它没有执行该功能。
它在浏览器控制台中给出错误cannot set property of null。
我试图通过函数 add() 中的 console.log('script is working') 检查 javascript,但它什么也没做
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="index.css">
<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>Document</title>
</head>
<body>
<script>
let Count_el = document.getElementById('c1')
let count = 0
function add(){
count +=1
Count_el.innerHTML = count
}
</script>
<h1 id='heading'>Count</h1>
<h2 id="c1">0</h2>
<button id="but_1" onclick="add()">Increment</button>
<br>
<button id="but_2" onclick="">Save</button>
<br>
<p id="data">Previous Entries: </p>
</body>
</html>
【问题讨论】:
标签: javascript html css