简体   繁体   English

JavaScript div onclick函数未执行

[英]JavaScript div onclick function not executing

On the square game, 2 player (1 player does not work yet), when a player wins, a div pops up and congratulates them. 在正方形游戏中,有2位玩家(1位玩家尚未工作),当一位玩家获胜时,会弹出一个div并向他们表示祝贺。 The div has an onclick function to close the div, but the onclick function doesn't appear to be executing and the div does not close. 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';
}

See it in action here 看到它在这里行动

您可以尝试以下方法:

 win.onclick = close;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM