以下是控制器代码:
let p2score
HTML代码:
const p1button = document
.querySelector('#p1')
.addEventListener('click', scoreUp);
const p2button = document
.querySelector('#p2')
.addEventListener('click', scoreUp);
let p2score = document.querySelector('#p2score').textContent;
let p1score = document.querySelector('#p1score').textContent;
function scoreUp(e) {
if (e.target.textContent === 'Player 1') {
p1score++;
console.log(p1score);
} else {
p2score++;
console.log(p2score);
}
}
当我单击“分配”时,应将id分配给文本框,并应提醒记录位置。但它显示未定义。谁能告诉我我做错了吗?