首页 > 解决方案 > 单击按钮时如何跳转到另一个 HTML 页面

问题描述

我一直在尝试使用 javascript 和 html 制作游戏,我想知道当用户单击 PLAY 按钮时有没有办法跳转到另一个 html 页面?此外,我要跳转到的 html 页面将成为加载屏幕,但现在它只是加载屏幕的背景。你有关于制作加载屏幕的任何提示吗?到目前为止,这是我的代码:

function Game_load() {
  window.location.href = "file:///home/chronos/u-56f297e83910b0d818c1d4b74fa15ed1c727cc9d/MyFiles/HTML,CSS,JS/loadingscreen.html";
}
body {
  background-image: url("https://thewallpapers.org/zoom/12916/Vista_Wallpaper_%2811%29.jpg");
}

.button_div {
  text-align: center;
}

.Play_text {
  text-align: center;
  top: 45%;
}

.play_button {
  background-color: #4CAF50;
  /* Green */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  position: absolute;
  top: 50%;
}

.play_button {
  border-radius: 4px;
}
<img src="https://www.freelogoservices.com/api/main/images/1j+ojl1FOMkX9WypfBe43D6kiP6CqhNGnx7IwXs1M3EMoAJtlSgthPNs8vw8" alt="Logo" width="210" height="140">

<div class="button_div">
  <button onclick="Game_load()" class="play_button"> PLAY </button>
</div>

标签: javascripthtml

解决方案


好吧,您需要清理一些代码。您的函数Game_load应该在函数的 init 之后有大括号,如下所示:

 function Game_Load(){
     window.location.href = "file:///home/chronos/u-56f297e83910b0d818c1d4b74fa15ed1c727cc9d/MyFiles/HTML,CSS,JS/loadingscreen.html";
}

推荐阅读