简体   繁体   English

在不重新加载的情况下切换选项

[英]Switch between tabs without reloading

I have two tabs in the content: Comerciales - Legales 我在内容中有两个标签: Comerciales - Legales

Each of these tabs should display a list of files, like the ones that are now displayed. 每个选项卡都应显示一个文件列表,如现在显示的文件。

I want to make that if the user clicks on Legales it hides the files of Comerciales tab and the tab becomes active (getting the active class and removing it from Comerciales ) and displaying only the files that belong to Legales. 我希望如果用户单击Legales,它会隐藏Comerciales选项卡的文件,并且该选项卡变为活动状态(获取活动类并从Comerciales中删除它)并仅显示属于Legales的文件。

I have tried with hide and fade in but I couldn't get the active class to the current tab. 我尝试过隐藏和淡入但我无法将活动类放到当前选项卡中。 Can someone help me out? 有人可以帮我吗?

Here it's my markup: 这是我的标记:

        <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>

See this fiddle: http://jsfiddle.net/MrZdh/ 看到这个小提琴: http//jsfiddle.net/MrZdh/

I've added some more classes to your markup so that it is easier to add jQuery handlers. 我已经为你的标记添加了一些类,以便更容易添加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 content (marked by corresponding class) is hidden via display:none by default. Legales内容(由相应的类标记)通过display:none默认隐藏。

Then tab click handlers can look like this: 然后选项卡单击处理程序可能如下所示:

    $('.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();
    });

Or yes, use some tabs plugin from kalpesh patel's answer. 或者是的,使用kalpesh patel的答案中的一些标签插件。

As you have not posted your JS code, I don't know where you are wrong: 由于你还没有发布你的JS代码,我不知道你错在哪里:

I would suggest that, you can use, jqueryui's tab: 我建议你可以使用jqueryui的标签:

http://jqueryui.com/tabs/ http://jqueryui.com/tabs/

There are numerous example demonstrating how to implement tabs. 有许多示例演示如何实现选项卡。 Google it. 谷歌一下。

Few more resources: 几乎没有资源:

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

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

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

I you are willing to use some already existing plug-in than try this one, you can easily get it working the way you want plus if you want to learn the tricks you can also play around with the code in it. 我愿意使用一些已经存在的插件而不是尝试这个插件,你可以轻松地按照你想要的方式工作,如果你想学习你也可以使用其中的代码。

Hope it helps. 希望能帮助到你。

jquery-content-panel-switcher jquery的内容面板的切换器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM