我正在创造一个Tic Tac Toe游戏。
页面加载后,html将重置为“开始页面”。所以我稍后将其添加回来,正文的原始html已存储在变量中。
当用户点击“开始”时按钮,然后加载原始HTML。
为什么现在不能正常工作?
(function () {
'useStrict';
// Grab original HTML and hold it as a variable
var originalHTML = document.body.innerHTML;
// When the page loads, the startup screen should appear.
window.onload = function() {
document.body.innerHTML = '<div class="screen screen-start" id="start"><header><h1>Tic Tac Toe</h1><a href="#" class="button">Start game</a></header></div>';
};
// Add programming, so that when the player clicks the start button the start screen disappears, the board appears, and the game begins.
function loadBoard() {
document.body.innerHTML = originalHTML;
};
document.querySelector('button').addEventListener("click", loadBoard);
})();
错误是:无法读取属性&#39; addEventListener&#39;是吗?
答案 0 :(得分:1)
Rebuild