JavaScript div onclick 函数未执行



在广场游戏中,2名玩家(1名玩家尚未工作(,当玩家获胜时,会弹出一个div并祝贺他们。div 有一个 onclick 函数来关闭div,但 onclick 函数似乎没有执行,div 也不会关闭。

  win.setAttribute('onclick', 'close()');
}
function on_win(winner) {
  document.getElementById('win').style.display = 'inline-block';
  document.getElementById('win_center').appendChild(winner);
}
function close() {
  console.log("close");
  document.getElementById('win').style.display = 'none';
}

在这里查看它的实际效果

你可以试试这个:

 win.onclick = close;

最新更新