javascript - 外部链接打不开

标签 javascript html

我对任何 JS 都是菜鸟,我有一个单页网站的菜单栏,可以滚动页面,但不会打开外部链接,请问你们中有人可以帮忙吗?代码如下,网址可查看http://protocol-labs.com/new

html

<div class="collapse navbar-collapse navbar-right" id="myNavbar">
    <ul class="nav navbar-nav">
        <li class="active"><a href="#banner">Home</a></li>
        <li class=""><a href="#service">Services</a></li>
        <li class=""><a href="#about">About</a></li>
        <li class=""><a href="#testimonial">Testimonial</a></li>
        <li class=""><a href="contact.html">Contact</a></li>        
    </ul>
</div>

导致问题的 js

(function ($) {

// Add smooth scrolling to all links in navbar
$(".navbar a,a.btn-appoint, .quick-info li a, .overlay-detail a").on('click', function(event) {
    event.preventDefault();
    var hash = this.hash;
    $('html, body').animate({
        scrollTop: $(hash).offset().top
    }, 900, function(){
        window.location.hash = hash;
    });
});

//jQuery to collapse the navbar on scroll
$(window).scroll(function() {
    if ($(".navbar-default").offset().top > 50) {
        $(".navbar-fixed-top").addClass("top-nav-collapse");
    } else {
        $(".navbar-fixed-top").removeClass("top-nav-collapse");
    }
});   
})(jQuery);

最佳答案

您已阻止将默认值附加到您的锚定事件。这会阻止链接工作。

$(".navbar a,a.btn-appoint, .quick-info li a, .overlay-detail a").on('click', function(event) {
        event.preventDefault(); // prevents link from working. Remove it and you should be good.

关于javascript - 外部链接打不开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45737360/

相关文章:

javascript - jquery 单击事件未在 Internet Explorer 上触发

html - 在设置像素 div 后填充 div 的其余部分

javascript - 想要激活当前的 <li>

html - 在 css 中更改输入搜索表单的背景颜色

html - 网站 html/css 右侧不需要的空白

javascript - Angular 8 : Assign Date Values to Type Moment

javascript - 单击另一个链接时尝试创建链接 "active"

html - 如果需要,带有 float 内容框和滚动条的动态高度弹出框

javascript - 如何在 jQuery 中定位不是具有特定类的容器子级的容器?

javascript - 如何在 cordova/phonegap 2.7.0 上实现 pdf.js 库?