【发布时间】:2021-07-06 04:33:44
【问题描述】:
每次单击buttonA 时,我都会尝试从lives 变量中减去1 条生命值。但是removeLives();函数在buttonA被点击之前执行。
<html lang="en">
<body>
<div id="lives"></div>
<button id="buttonA" onClick="removeLives()">buttonA</button>
<script>
var lives = 3;
document.getElementById("lives").innerHTML="LIVES: " + removeLives();
document.getElementById("buttonA").onClick = function(){
removeLives() {
lives--;
return lives;
}
}
</script>
</body>
</html>
【问题讨论】:
-
你在加载脚本时调用 removeLives() ?
标签: javascript function button onclick click