[英]Button not appearing when game ends
I want a restart a game after it ends with a button, but I don't want it to appear until you crash. 我希望在按钮结束后重新启动游戏,但是我不希望它在崩溃之前出现。
I have tried this code: 我已经试过这段代码:
if (myGamePiece.crashWith(myObstacles[i])) {
myGameArea.stop;
var button = document.createElement("button");
button.innerHTML = "Restart";
var body = document.getElementByTagName("body")[0];
body.appendChild(button);
return;
}
The button does not appear. 该按钮不出现。 Can you help me fix this? 你能帮我解决这个问题吗? Update: I have tried making the button be hidden and then not, but that doesn't work. 更新:我尝试过隐藏按钮,然后隐藏起来,但这不起作用。 I have tried doing it the way that someone (sorry) suggested and that created and infinite number of buttons. 我已经尝试过以某人(对不起)建议的方式进行操作,并创建了无数个按钮。
It does not appear because there is a little error in your script. 因为您的脚本中有一点错误,所以它没有出现。
var body = document.getElementByTagName("body")[0];
should be 应该
var body = document.getElementsByTagName("body")[0];
As a side note, if you want to append a dynamically created html element to the body it's sufficient to write: 附带说明一下,如果要将动态创建的html元素追加到主体,则只需编写以下内容:
document.body.appendChild(button);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.