2016-07-04 7 views
0

私のウェブサイト(タブ内のタブ、具体的にはタブ)を作成するために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

+0

あなたはライブデモください – Li357

+0

@AndrewLを含めることができます。はい、ライブデモはこちらです:http://jsfiddle.net/rohankumar1524/x5528/ – curiousk

+0

不要なタグを使用しないでください... –

答えて

1

変更以下:

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

前に、内容を点滅していないために優れているすべてのコンテンツ

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

したり、そのコードを削除し、CSS非表示にしますスクリプトにはそれを隠す機会があります

.tab_content {display;none} 

DEMO

+0

ありがとうございます、それは動作しますが、アクティブなクラスは最初のアイテムに残りますが、たとえそうでなくても、アクティブなアイテムのようなスタイルにすることができます。それを修正することは可能ですか? – curiousk

+0

'$ active.addClass( 'active');の最初のインスタンスを削除します; – charlietfl

+0

はい、それはトリックでした、ありがとうございました。 :) – curiousk

関連する問題