Javascript 无法使用在setInterval函数范围内定义的参数。@biberman-hmm,这看起来对我的情况很有用,谢谢!这是行不通的,因为参数“hole”是在计时器内部定义的,所以它不能从外部调用它。 //gid const grid = document.qu
Javascript 无法使用在setInterval函数范围内定义的参数。@biberman-hmm,这看起来对我的情况很有用,谢谢!这是行不通的,因为参数“hole”是在计时器内部定义的,所以它不能从外部调用它。 //gid const grid = document.qu,javascript,dom-events,Javascript,Dom Events,无法使用在setInterval函数范围内定义的参数。@biberman-hmm,这看起来对我的情况很有用,谢谢!这是行不通的,因为参数“hole”是在计时器内部定义的,所以它不能从外部调用它。 //gid const grid = document.querySelector('.grid'); //score display value const scoreValue = document.querySelector('#scoreValue'); //score let score =
无法使用在setInterval函数范围内定义的参数。@biberman-hmm,这看起来对我的情况很有用,谢谢!这是行不通的,因为参数“hole”是在计时器内部定义的,所以它不能从外部调用它。
//gid
const grid = document.querySelector('.grid');
//score display value
const scoreValue = document.querySelector('#scoreValue');
//score
let score = 0;
const timer = setInterval(() => {
//output random number
let output = Math.floor(Math.random() * 16);
//select hole
let hole = document.getElementById(output);
hole.innerHTML = '<img src="img/kiseki.png" alt=""></img>';
setTimeout(() => {
hole.innerHTML = '';
}, 2000);
grid.addEventListener('click', e => {
if (e.target.tagName === "IMG") {
score++;
scoreValue.textContent = score;
console.log(score);
hole.innerHTML = '';
}
});
}, 4000);
const grid = document.querySelector('.grid');
const scoreValue = document.querySelector('#scoreValue');
const newMoleTimer = 4000;
const moleTimeout = 2000
let score = 0;
let hole;
grid.addEventListener('click', e => {
if (e.target.tagName === "IMG") {
score++;
scoreValue.textContent = score;
if(hole) hole.innerHTML = '';
}
});
const timer = setInterval(() => {
let output = Math.floor(Math.random() * 16);
hole = document.getElementById(output);
hole.innerHTML = '<img src="img/kiseki.png" alt=""></img>';
setTimeout(() => {
hole.innerHTML = '';
}, moleTimeout);
}, newMoleTimer);