javascript - 单击按钮时如何跳转到另一个 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>
解决方案
好吧,您需要清理一些代码。您的函数Game_load
应该在函数的 init 之后有大括号,如下所示:
function Game_Load(){
window.location.href = "file:///home/chronos/u-56f297e83910b0d818c1d4b74fa15ed1c727cc9d/MyFiles/HTML,CSS,JS/loadingscreen.html";
}
推荐阅读
- git - Azure Web 应用程序部署输出占用了 bitbucket 管道分钟数
- apache-spark - 使用广播应用地图转换时,pyspark Udf 未按预期工作?
- google-apps-script - 当用户已经在作曲家中时,如何从我的 gmail 插件创建独立的草稿消息?
- javascript - minimum and maximum values of keys - group
- javascript - Rewrap text wrapped with wrong marks/brackets
- git - When I use 'rm -rf .git ' then 'git init', the source files are disappear?
- python - Python - Download files from SharePoint site
- c# - URL Not loading in a System.Windows.Forms.WebBrowser
- javascript - check if data has been loaded before passing as a prop react/redux
- c# - ASP.NET Core MVC application with Identity Core and Entity Framework 6