当用户单击图像时,我正在尝试使用以下代码将变量“current”写入 div“bank”:
document.getElementById('bank').innerHTML = current
根据我的研究,这应该有效,但事实并非如此。这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/default.css">
<script>
var current = 0;
var totalThisGame = 0;
function onButtonClick
{
current = current +1;
totalThisGame = totalThisGame +1;
document.getElementById('bank').innerHTML = current;
}
</script>
</head>
<body>
<div id="left">
<div id="bank">
</div>
<img id="image" src="img/image.png" alt="image" onclick=onButtonClick();>
</div>
<div id="middle">
</div>
<div id="right">
</div>
</body>
</html>