一个href不会去其他页面 [英] a href is not going to other pages

查看:135
本文介绍了一个href不会去其他页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个导航菜单,其链接指向同一index.html的不同部分,例如 href =#about href =#product但是当我输入 href =reservation.html时,它不会转到该页面。换句话说,所有同页内部锚链接都有效,但外部链接(到其他页面)不起作用。知道为什么吗?
我正在使用bootstrap:

I have this navigation menu that has few links to different part of the same index.html like a href="#about" or a href="#product" but when i put a href="reservation.html" it does not go to that page. in other word, all same-page internal anchor link works but external links (to other pages) does not work. any idea why? I am using bootstrap:

<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> 


推荐答案

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

OK problem solved it seems that at the bottom of the index.html of this one-page template there is this line:

$(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语句:

the links as i guessed are prevented by default so i added an if statement saying:

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

这篇关于一个href不会去其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆