简体   繁体   English

导航栏链接不起作用

[英]Nav bar links not working

I am making a website using bootstrap. 我正在使用Bootstrap建立网站。 I have made a nav bar where I want the menu items to link to the different sites. 我做了一个导航栏,我希望菜单项链接到不同的站点。 However it is not working at all - it is usually never a problem getting links to work, but I am new in using Bootstrap and i feel like I'm missing something - do you need to have a js code to get your links to work? 但是,它根本不起作用-通常,链接正常工作从来都不是问题,但是我是Bootstrap的新手,我感觉自己缺少一些东西-您是否需要一个JS代码才能使链接正常工作? Normally I just write something like I have put all the sites in the same folder and I have tried so many things now. 通常,我只是写一些东西,就像我将所有站点都放在同一个文件夹中,而我现在尝试了很多事情。 I have also tried giving the items and ID and then adding a js code, but nothing happens. 我也尝试过给出项目和ID,然后添加js代码,但没有任何反应。

 $(document).ready(function() { $('#aboutus').on('click', function() { location.href = "About kopi.html"; }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> <div class="container-fluid"> <nav class="row navbar navbar-expand-lg navbar-light bg-light"> <a class="navbar-brand" href="#">Name</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav ml-auto"> <li class="nav-item"> <a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a class="nav-link" href="Portfolio.html">Portfolio</a> </li> <li class="nav-item"> <a class="nav-link" href="About kopi.html" id="aboutus">About</a> </li> </ul> </div> </nav> </div> 

Hi Maria and welcome to Stack Overflow. 嗨,玛丽亚,欢迎来到Stack Overflow。

The syntax for your a tag is correct. 你的语法a标签是正确的。 And thus it should work. 因此,它应该工作。

Saying that your link doesn't work, is extremely vague. 说您的链接无效是非常模糊的。 What you could try: 您可以尝试的方法:

  • Make sure all your styles and scripts from Bootstrap are loaded. 确保从Bootstrap中加载了所有样式和脚本。 (This includes dependencies such as jQuery and Popper.js) (这包括jQuery和Popper.js之类的依赖项)
  • Make sure the pages you're referring actually exist. 确保您要引用的页面确实存在。 (Does this file: Portfolio.html exist?) (此文件: Portfolio.html存在吗?)

It looks like you're using some classes that are specific to Bootstrap 4 in your markup, but including the Bootstrap 3 JS and CSS. 看起来您在标记中使用了一些特定于Bootstrap 4的类,但包括Bootstrap 3 JS和CSS。

Try using the Bootstrap 4 files instead: 尝试改用Bootstrap 4文件:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"/>

Here's a fiddle I created to try to reproduce your problem. 我创建了一个小提琴来尝试重现您的问题。 It seems to work with the Bootstrap 4 files: 它似乎可以与Bootstrap 4文件一起使用:

https://jsfiddle.net/bbz0t198/ https://jsfiddle.net/bbz0t198/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM