簡體   English   中英

在不重新加載的情況下切換選項

[英]Switch between tabs without reloading

我在內容中有兩個標簽: Comerciales - Legales

每個選項卡都應顯示一個文件列表,如現在顯示的文件。

我希望如果用戶單擊Legales,它會隱藏Comerciales選項卡的文件,並且該選項卡變為活動狀態(獲取活動類並從Comerciales中刪除它)並僅顯示屬於Legales的文件。

我嘗試過隱藏和淡入但我無法將活動類放到當前選項卡中。 有人可以幫我嗎?

這是我的標記:

        <ul class="pdf_documents clearfix">
            <li class="active"><a href="javascript:void(0)">Comerciales</a></li>
            <li><a href="javascript:void(0)">Legales</a></li>
        </ul>
        <div class="pdf_box">
            <div class="pdf_file">
                <img src="images/pdf.png" alt="pdf" width="70" height="70">
                <p>Ficha Técnica</p>
            </div>
            <div class="pdf_file">
                <img src="images/pdf.png" alt="pdf" width="70" height="70">
                <p>Ficha Descriptiva</p>
            </div>
            <div class="pdf_file">
                <img src="images/pdf.png" alt="pdf" width="70" height="70">
                <p>Último informe</p>
            </div>
            <div class="pdf_file">
                <img src="images/pdf.png" alt="pdf" width="70" height="70">
                <p>Informes anteriores</p>
            </div>
            <div class="pdf_file">
                <img src="images/pdf.png" alt="pdf" width="70" height="70">
                <p>Folleto completo</p>
            </div>
        </div>

看到這個小提琴: http//jsfiddle.net/MrZdh/

我已經為你的標記添加了一些類,以便更容易添加jQuery處理程序。

    <ul class="pdf_documents clearfix">
        <li class="tab-com active"><a href="javascript:void(0)">Comerciales</a></li>
        <li class="tab-leg"><a href="javascript:void(0)">Legales</a></li>
    </ul>
    <div class="pdf_box">
        <div class="pdf_file comerciales">
            <img src="images/pdf.png" alt="pdf" width="70" height="70">
            <p>Ficha Técnica</p>
        </div>
        <div class="pdf_file legales">
            <img src="images/pdf.png" alt="pdf" width="70" height="70">
            <p>Ficha Descriptiva</p>
        </div>
        <div class="pdf_file comerciales">
            <img src="images/pdf.png" alt="pdf" width="70" height="70">
            <p>Último informe</p>
        </div>
        <div class="pdf_file legales">
            <img src="images/pdf.png" alt="pdf" width="70" height="70">
            <p>Informes anteriores</p>
        </div>
        <div class="pdf_file comerciales">
            <img src="images/pdf.png" alt="pdf" width="70" height="70">
            <p>Folleto completo</p>
        </div>
    </div>

Legales內容(由相應的類標記)通過display:none默認隱藏。

然后選項卡單擊處理程序可能如下所示:

    $('.tab-com a').click(function(e){
        //make all tabs inactive
        $('.pdf_documents a').removeClass('active');
        //then make the clicked tab active
        $(this).addClass('active');    
        $('.pdf_box .legales').hide();
        $('.pdf_box .comerciales').show();
    });


    $('.tab-leg a').click(function(e){
        //make all tabs inactive    
        $('.pdf_documents a').removeClass('active');
        //then make the clicked tab active
        $(this).addClass('active');
        $('.pdf_box .comerciales').hide();
        $('.pdf_box .legales').show();
    });

或者是的,使用kalpesh patel的答案中的一些標簽插件。

由於你還沒有發布你的JS代碼,我不知道你錯在哪里:

我建議你可以使用jqueryui的標簽:

http://jqueryui.com/tabs/

有許多示例演示如何實現選項卡。 谷歌一下。

幾乎沒有資源:

http://www.jacklmoore.com/notes/jquery-tabs

http://jqueryfordesigners.com/jquery-tabs/

http://www.apricot-studios.com/lab/jquery/jquery-tabs-tutorial.php

我願意使用一些已經存在的插件而不是嘗試這個插件,你可以輕松地按照你想要的方式工作,如果你想學習你也可以使用其中的代碼。

希望能幫助到你。

jquery的內容面板的切換器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM