简体   繁体   English

用js加载导航栏,然后用js激活导航栏内的下拉菜单

[英]Load navbar with js then activating dropdown menu within navbar with js

I am trying to load the NavBar for each html page, instead of copy and pasting it into multiple html pages. 我正在尝试为每个html页面加载NavBar,而不是将其复制并粘贴到多个html页面中。 This works fine, however I also have another function to activate the dropdown menu of the NavBar on hover, this function is not working. 这可以正常工作,但是我还有另一个功能可以在悬停时激活NavBar的下拉菜单,此功能无法正常工作。 How do I get this to work? 我该如何工作?

HTML: HTML:

<div id="nav"></div>

JS: JS:

$(document).ready(function(){

// Loading NavBar
$("#nav").load("nav.html");


// Activating dropdown menu
$(".top-nav-item").hover(            
    function() {
        $('.dropdown-menu', this).not('.in .dropdown-menu').stop(true,true);
        $(this).toggleClass('open');        
    },
    function() {
        $('.dropdown-menu', this).not('.in .dropdown-menu').stop(true,true);
        $(this).toggleClass('open');       
    }
);

});

You could use: 您可以使用:

dropDownMenu.onmouseover = function() {codeToOpenDropDownMenu};

and for closing: 和关闭:

dropDownMenu.onmouseout = function() {codeToCloseDropDownMenu};

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

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