0

jquery タブを使用して一部のコンテンツを表示しています。別のタブを開くには、タブ内にリンクを作成する必要があります。私の jquery の知識は非常に限られているため、コードを投稿しているので、何ができるかを確認して確認できます。

これはjqueryコードです:

$(document).ready(function() {
    //$(".tab_content").hide(); 
    $(".tab_content").css({
        'display':'block',
        'position':'absolute',
        'top':'-999em',
        'left':'-999em'
    });
    //$(".tab_content:first").show(); 
    $(".tab_content:first").css({
        'top':'350px',
        'left':'50px',
        'width':'660px'
    });
    firstTabHeight = $(".tab_content:first").height();
    $(".tab_content:first").parent().css('height',firstTabHeight);

    $("#nav-portfolio ul li").click(function() {
        $("#nav-portfolio ul li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        //$(".tab_content").hide(); //Hide all tab content
        $(".tab_content").css({
            'display':'block',
            'position':'absolute',
            'top':'-999em',
            'left':'-999em'
        });

        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).hide(); 
        //$(".tab_content").css({
        //  'opacity':'0',
        //});
        //var tabHeight = $(activeTab).height();
        //$('#colLeft').height(tabHeight);
        $(activeTab).fadeIn(); //Fade in the active content
        thisTabHeight = $(activeTab).height();
        $(activeTab).css({
            'display':'block',
            'position':'relative',
            'top':'0',
            'left':'0',
            'width':'660px'
        });
    activeTabHeight = $(activeTab).height();
    $(".tab_content:first").parent().css('height',activeTabHeight);

   return false;

    });
4

1 に答える 1

0

クリック関数をタブ内のリンクにバインドして、移動したいタブのクリック関数を呼び出します。たとえば、リンクで2番目のタブをトリガーする場合:

$('#this_is_the_link').click(function(e) {
    e.preventDefault(); //stop the normal link function from happening
    $("#nav-portfolio ul li:nth-child(2)").click() // call click event on the second tab
});
于 2012-06-27T04:47:08.903 に答える