使用活动的javascript创建菜单?

使用活动的javascript创建菜单?,javascript,html,Javascript,Html,我有这个密码 $('ul.navi').each(function () { // For each set of tabs, we want to keep track of // which tab is active and it's associated content var $active, $content, $links = $(this).find('a'); // If the location.hash matches one of the links, use tha

我有这个密码

$('ul.navi').each(function () {
// For each set of tabs, we want to keep track of
// which tab is active and it's associated content
var $active, $content, $links = $(this).find('a');

// If the location.hash matches one of the links, use that as the active tab.
// If no match is found, use the first link as the initial active tab.
$active = $($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);
$active.addClass('active');

$content = $($active[0].hash);

// Hide the remaining content
$links.not($active).each(function () {
$(this.hash).hide();
});

// Bind the click event handler
$(this).on('click', 'a', function(e){
// Make the old tab inactive.
$active.removeClass('active');
$content.hide();

// Update the variables with the new link and content
$active = $(this);
$content = $(this.hash);

// Make the tab active.
$active.addClass('active');
$content.show();

// Prevent the anchor's default click action
e.preventDefault();
});
});
我想向“Licensicatura”和“MEstrado”显示文本,一次显示一个,而不是同时显示两个。
另一个问题是活动类,只需要一次显示一个活动项,而不是“Licensicatura”和“Mestrado”

您可以这样做:

$('ul.navi').on('click', 'a', function (e) {
    //Change content displayed
    $($("ul.navi a.active")[0].hash).hide();      
    $(this.hash).show();

    //Change active item
    $("ul.navi a.active").removeClass("active");    
    $(this).addClass("active");  

    e.preventDefault();
});

//Hide all content divs except first one
$("ul.navi a").each(function(index){
    if(index != 0)
        $(this.hash).hide();
    else
        $(this).addClass("active");
});

请在此处查看:

问题已解决!谢谢