我建立了一个计数器,但如果值 = 4,我无法自动重置计数器
<!DOCTYPE html>
<html>
<body>
<span class="hits"> 0 </span>
<button onclick="resetHits()" class="tryagain">RESTART</button>
<script>
var hits = 0;
var hitElement = document.querySelector('.hits');
document.body.onkeyup = function(e) {
if(e.keyCode == 32) {addHit()}}
var addHit = function() {hits++; renderHits()}
var renderHits = function() {hitElement.innerHTML = hits}
var resetHits = function() {hits = 0; renderHits()}
</script>
</body>
</html>
蛊毒传说
ABOUTYOU
小怪兽爱吃肉
相关分类