gpt4 book ai didi

javascript - 如何让我的按钮导航到不同的页面?

转载 作者:行者123 更新时间:2023-12-03 00:23:41 25 4
gpt4 key购买 nike

我想要一个带有导航按钮栏的主页,每个按钮在我的代码中打开一个不同的页面,并有一个“返回”按钮返回主页。我不知道如何使页面 html 代码在主页中看不到,当我单击按钮时,它们会出现(我更喜欢向右滑动动画),当我单击返回按钮时,它将向左滑动返回主屏幕例如,这是我的代码:

nav.nav-center ul {
text-align: center;
}

nav.nav-center ul li {
display: inline;
float: none;
}

nav.nav-center ul li a {
display: inline-block;
}
<!DOCTYPE html>
<html>

<head>

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" integrity="sha384-PmY9l28YgO4JwMKbTvgaS7XNZJ30MK9FAZjjzXtlqyZCqBY6X6bXIkM++IkyinN+" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!-- Optional theme -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap-theme.min.css" integrity="sha384-jzngWsPS6op3fgRCDTESqrEJwRKck+CILhJVO5VvaAZCq8JYf8HsR/HPpBOOPZfR" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js" integrity="sha384-vhJnz1OVIdLktyixHY4Uk3OHEwdQqPppqYR8+5mjsauETgLOcEynD9oPHhhz18Nw" crossorigin="anonymous"></script>

<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>

<meta name="viewport" content="width=device-width, initial scale=1">

</head>
<style>

</style>

<body>
<nav class="nav-center" role="navigation">
<div class="nav-wrapper container">
<ul>
<li><a class="waves-effect waves-light btn">Button1</a></li>
<li><a class="waves-effect waves-light btn">Button2</a></li>
</ul>
</div>
</nav>

<h4>This is supposed to be shown only after clicking the button1</h4>
<p>i want the button to navigate the page so this will be shown only after button 1 is clicked</p>

<h4>This is supposed to be shown only after clicking the button2</h4>
<p>i want the button to navigate the page so this will be shown only after button 2 is clicked</p>


</body>

</html>

我只想看到主页中的按钮,当我单击它们时,将出现没有按钮的新页面,带有返回主页按钮,并且具有应该根据每个按钮的文本。我现在所拥有的是一次性显示整个 html 代码,并且没有页面划分

最佳答案

您必须创建单独的 HTML 文件才能在不同的路线上显示。如果您是初学者,我已在此链接上更改了您的代码

Online Code

编辑:解释代码

为button1和button2创建两个文件(例如a.html b.html)并相应地粘贴其内容。

并在index.html中删除您复制到a.html和b.html的代码。

在index.html中 -

<a href="a.html" class="waves-effect waves-light btn">Button1</a>
<a href="b.html" class="waves-effect waves-light btn">Button2</a>

它应该可以工作。

关于javascript - 如何让我的按钮导航到不同的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54195356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com