javascript - 有没有办法将游戏代码放在选项卡中
问题描述
我刚刚制作了可以链接到不同 html 文件的工作选项卡。我想知道如何将游戏代码添加到选项卡内,或者您只能放置类似的段落和链接。
我是 html 的新手,所以我不知道如何格式化它以将我的游戏的第一部分放在第一个选项卡中。
这是我的代码:
<!Doctype html>
<html>
<head>
<title> Basic Clicker</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="nav_bar">
<ul>
<li><a href="index.html" id="onlink">Home</a></li>
<li><a href="skilltree.html">SkillTree</a></li>
<li><a href="equipment.html">Equipment</a></li>
<li><a href="pets.html">Pets</a></li>
<li><a href="skills.html">Skills</a></li>
<li><a href="quests.html">Quests</a></li>
</ul>
</div>
<div class="main_container">
<p> This is the home page.</p>
</div>
</body>
</html>
这是我的点击游戏:
<html>
<head>
<link rel="stylesheet" type="text/css" href="interface.css" />
</head>
<title> Basic Clicker</title>
<body>
<style>
div,a {
text-align: center;
}
</style>
<div class="a">
<span id="cookies">0</span>
<br />
<button onclick="cookieClick(1)">Click Me!</button>
<br />
Cost: <span id="cursorCost">10</span><button
onclick="buyAnt()">Buy Ant</button>
<br />
Cursors: <span id="cursors">0</span>
<br />
Cost: <span id="cursorCost">10</span>
<script type="text/javascript" src="main.js"></script>
</div>
</body>
</html>
我希望能够将我的答题器游戏的第一部分放在第一个选项卡中,就目前而言,我在我的第一个选项卡中得到“这是主页”(除了我知道的链接之外唯一有效的东西)我不确定如何格式化它以使我的答题器进入第一个选项卡。如果有可能看到我之前的问题,但我的第一个问题中包含 css 选项卡格式代码。
解决方案
我想知道如何将游戏代码添加到选项卡内,或者您只能放置类似的段落和链接
您可以将任何有效的 HTML 放入任何有效的 HTML 中。
现在来解决您要在这里完成的任务:一个选项卡式游戏,可能类似于群模拟器,您可以在其中导航多个视图(设备、技能)。
您可以使用一些 CSS 和 javascript 轻松完成此操作,请参见以下W3 片段:
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
body {font-family: Arial;}
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>Tabs</h2>
<p>Click on the buttons inside the tabbed menu:</p>
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
</body>
</html>
或者,以及更接近地模仿您当前安排的实现,您可以使用 AJAX 请求来加载您在链接中引用的 HTML 页面。然而,这增加了相当多的复杂性,所以可能从标签开始,看看是否足够。
推荐阅读
- mysql - 使用 GROUP BY 时的复杂条件列
- javascript - 实现下拉单击忽略选项
- c# - 用字符串中的单个字符修剪重复字符
- javascript - Eclipse - 未定义的属性名称警告
- sql - SQL 错误 (102):“=”附近的语法不正确
- python - 如何将 2D 和 1D 类(分别为单热编码和常规整数)的混合输入到 Keras 序列模型中?
- java - android - java.lang.ArrayIndexOutOfBoundsException:长度=4;index = 4长度数组 - Thinbug
- marklogic - 使用管理 API 在 MarkLogic 9.2 上设置元数据字段
- django - 在 Django 默认环境之外的数据库中替换/更改文件路径
- portal - 我可以从 TFS/VSTS 发布 Dynamics 365 门户页面吗