1

あなたの助けが必要です!

私のサイトにはjqueryによるタブ機能があります。そしてそれはうまくいきます。

これが<head>のjavascriptです

<script type="text/javascript">
// When the document loads do everything inside here ...
$(document).ready(function(){
    // When a link is clicked
    $("a.tab").click(function () {
    // switch all tabs off
    $(".active").removeClass("active");
    // switch this tab on
    $(this).addClass("active");
    // slide all content up
    $(".content").slideUp();
    // slide this content up
    var content_show = $(this).attr("title");
    $("#"+content_show).slideDown();
    });
});
</script>

とhtmlソースはここにあります!

<ul id="tabs">
    <li><a href="#" title="type1" class="tab active">type1</a></li>
    <li><a href="#" title="type2" class="tab">type2</a></li>
</ul>
<section id="type1" class="content">
    <p>contents1contents1contents1contents1contents1</p>
</section>
<section id="type2" class="content content_2">
    <p>contents2contents2contents2contents2</p>
</section>

しかし、ボタンを特定のタブにリンクする必要があります。カテゴリアーカイブページにボタンがあり、ユーザーがボタンをクリックすると、ページが開き、2番目のタブに「type2」という名前のIDが表示されます。

上記のソースはこのページ で参照されており、これが私が取り組んでいるページです。

アドバイスをお待ちしております!

4

1 に答える 1

1

上記のhtmlファイルの名前がindex.htmlであるとすると、次のようなリンクを作成できます。

<a href="index.html#!type2">click</a>

それで:

$(document).ready(function(){
    function doTab() {
        $(".active").removeClass("active");
        $(this).addClass("active");
        $(".content").slideUp();
        var content_show = $(this).attr("title");
        $("#"+content_show).slideDown();
    }

    // When a link is clicked
    $("a.tab").click(doTab);

    if (window.location.hash) {
        $('a[title="' + window.location.hash.substring(2) + '"]').click();
    }
});
于 2012-04-26T04:48:32.460 に答える