单击按钮时如何跳转到另一个HTML页面

时间:2020-01-28 14:46:50

标签: javascript html

我一直在尝试用javascript和html制作游戏,我想知道当用户单击“播放”按钮时,是否有办法跳到另一个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>

1 个答案:

答案 0 :(得分:2)

好吧,您需要清理一下代码。 函数Game_load在函数初始化后应带有大括号,如下所示:

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