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



我想要一个带有导航按钮栏的主页,每个按钮在我的代码中打开一个不同的页面,并有一个"返回"按钮返回主页。我不知道如何使页面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 文件以显示在不同的路由上。如果您是初学者,我已经在此链接上更改了您的代码

在线代码

编辑:解释代码

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

并在索引中.html删除已复制到 A.html 和 B.html 的代码。

在索引中.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>

它应该有效。

相关内容

  • 没有找到相关文章

最新更新