Javascript a href不会转到其他页面

Javascript a href不会转到其他页面,javascript,jquery,html,twitter-bootstrap,hyperlink,Javascript,Jquery,Html,Twitter Bootstrap,Hyperlink,我有一个导航菜单,它几乎没有指向同一index.html不同部分的链接,比如href=“#about”或href=“#product”,但当我放置href=“reservation.html”时,它不会进入该页面。换句话说,所有相同页面的内部锚定链接都有效,但外部链接(到其他页面)不起作用。知道为什么吗? 我正在使用引导: <nav class="navbar navbar-default navbar-fixed-top"> <div class="container"&

我有一个导航菜单,它几乎没有指向同一index.html不同部分的链接,比如
href=“#about”
href=“#product”
,但当我放置
href=“reservation.html”
时,它不会进入该页面。换句话说,所有相同页面的内部锚定链接都有效,但外部链接(到其他页面)不起作用。知道为什么吗? 我正在使用引导:

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a href="index.html"><img src="image/logo.png"></a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav navbar-right" id="font">
        <li><a href="#about">ABOUT</a></li>
        <li><a href="#services">SERVICES</a></li>
        <li><a href="#portfolio">PORTFOLIO</a></li>
        <li><a href="#pricing">PRICING</a></li>
        <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">EVENTS <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Wedding</a></li>
            <li><a href="#">Bachelor Party</a></li>
            <li><a href="#">Prom</a></li>
          </ul>
        </li>
        <li><a href="reservation.html">RESERVATION</a></li>
        <li><a href="#contact">CONTACT</a></li>

      </ul>
    </div>
  </div>
</nav> 


尝试使用
href=“/reservation.html”
如果确切链接是
www.website.com/reservation.html
尝试使用
href=“/reservation.html”
如果确切链接是
www.website.com/reservation.html
您需要了解相对路径

/
根目录

/
当前目录

。/
当前目录的父目录

试试这个

<a href="./index.html"><img src="image/logo.png"></a>

您需要了解相对路径

/
根目录

/
当前目录

。/
当前目录的父目录

试试这个

<a href="./index.html"><img src="image/logo.png"></a>

确定问题已解决此单页模板的index.html底部似乎有以下行:

$(document).ready(function(){
  // Add smooth scrolling to all links in navbar + footer link
  $(".navbar a, footer a[href='#myPage']").on('click', function(event) {

    // Prevent default anchor click behavior
    event.preventDefault();

    // Store hash
    var hash = this.hash;

    // Using jQuery's animate() method to add smooth page scroll
    // The optional number (900) specifies the number of milliseconds it takes to scroll to the specified area
    $('html, body').animate({
      scrollTop: $(hash).offset().top
    }, 900, function(){

      // Add hash (#) to URL when done scrolling (default click behavior)
      window.location.hash = hash;
    });
  });
我猜测的链接在默认情况下是被阻止的,因此我添加了一条if语句,其中说:

 if (".navbar a" =! ".external"){here goes the rest of li that have external links and now it works}

好的,问题解决了。似乎在这个单页模板的index.html底部有一行:

$(document).ready(function(){
  // Add smooth scrolling to all links in navbar + footer link
  $(".navbar a, footer a[href='#myPage']").on('click', function(event) {

    // Prevent default anchor click behavior
    event.preventDefault();

    // Store hash
    var hash = this.hash;

    // Using jQuery's animate() method to add smooth page scroll
    // The optional number (900) specifies the number of milliseconds it takes to scroll to the specified area
    $('html, body').animate({
      scrollTop: $(hash).offset().top
    }, 900, function(){

      // Add hash (#) to URL when done scrolling (default click behavior)
      window.location.hash = hash;
    });
  });
我猜测的链接在默认情况下是被阻止的,因此我添加了一条if语句,其中说:

 if (".navbar a" =! ".external"){here goes the rest of li that have external links and now it works}

不工作意味着锚点击没有效果或显示错误页面?当你说它不工作时,你是什么意思?它不起作用还是给你一个错误?是
index.html
还是
reservation.html
,两者都在同一个目录/文件夹中?它们在同一个目录中。不工作意味着锚定单击无效或显示错误页面?当你说它不工作时,你是什么意思?它不起作用还是给你一个错误?是
index.html
还是
reservation.html
,两者都在同一个目录/文件夹中?它们在同一个目录中。试着把整个链接放在一起检查它是否真的存在。链接在url中甚至没有改变,一定有e.preventDefualt。当我排除jquery.min.js时,它会工作。请尝试放置整个链接以检查它是否确实存在。该链接在url中甚至没有更改,必须在某个地方有e.preventDefualt。当我排除jquery.min.js时works@AliRJindex.html和reservation.html在哪里?两者都在同一个目录中?你得到了什么结果?是的。当我点击reservation时,它甚至不会改变url中的任何内容,当我排除jquery.min.js时,必须在某个地方设置默认值。链接工作正常。@AliRJ index.html和reservation.html在哪里?两者都在同一个目录中?你得到了什么结果?是的。当我点击reservation时,它甚至不会改变url中的任何内容,当我排除jquery.min.js链接时,一定会有默认值。