Jquery选项卡默认情况下没有活动的选项卡

时间:2016-07-04 19:28:03

标签: jquery

我正在使用下面的jQuery在我的网站上创建选项卡(选项卡中的选项卡,具体而言),但我希望默认情况下没有活动选项卡。首次访问该页面时,应关闭所有标签页。

我可以在下面看到有关设置初始活动标签的评论,但我无法弄清楚要更改/删除的内容以防止它执行此操作。有人可以帮忙吗?

jQuery('ul.tabs').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 = jQuery(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 = jQuery($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);
$active.addClass('active');

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

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

// Bind the click event handler
jQuery(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 = jQuery(this);
    $content = jQuery(this.hash);

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

    // Prevent the anchor's default click action
    e.preventDefault();
});
});

Live Demo

1 个答案:

答案 0 :(得分:1)

更改以下内容:

$links.not($active).each(function () {
    jQuery(this.hash).hide();
});

$links.each(function () {
    jQuery(this.hash).hide();
});

或删除该代码并在css中隐藏所有内容,这些内容最好不会在脚本有机会隐藏内容之前不闪存内容

.tab_content {display:none}

DEMO