简体   繁体   English

仅显示要单击的选项卡的内容

[英]only show the content for which tab to clicked

I am trying to use tab navigation and based on which tab is clicked, I need to show content based on that tab and hide the content belong to other tabs. 我正在尝试使用选项卡导航,并基于单击哪个选项卡,我需要基于该选项卡显示内容并隐藏属于其他选项卡的内容。 I have included tab section, inner html where tab content goes and javascript to do this. 我包括选项卡部分,选项卡内容所在的内部html和javascript以实现此目的。 Not working, any ideas what I am missing? 不起作用,有什么想法我想念吗? tab section of the page 页面的标签部分

<ul class="wui-tab-nav">
    <li class="wui-first"><a class="wui-link" href="index.html">Home </a></li>
    <li class="wui-sub" id="vol"><a class="wui-link" href="#Vol" rel="tabs1">Business Volume </a></li>
    <li class="wui-sub"><a class="wui-link" href="#Vol2"  rel="tabs2">Infras Volume</a></li>
    <li class="wui-sub"><a class="wui-link" href="#Vol3"  rel="tabs3" >Database Volume</a></li>
    <li class="wui-sub"><a class="wui-link" href="#Vol4"  rel="tabs4">Customer Volume</a></li>
</ul>

Div section to put the tab content Div部分放置标签内容

<DIV id=chart class=wui-inpage-container style="float:left; display: block; overflow: hidden; padding:0; margin:0 auto; border:0;">
    <ul class="tab-content" id="tabs1"> 
            <li id="business_vol1"></li>
            <li id="business_vol2"></li>
            <li id="business_vol3"></li>
            <li id="business_vol4"></li>    
    </ul>

    <ul class="tab-content" id="tabs2"> 
            <li id="Infras1"></li>
            <li id="Infras2"></li>
            <li id="Infras3"></li>                    
    </ul>
</DIV>

javascripts to show only the click tab content 仅显示点击标签内容的javascripts

<script type="text/javascript">
    $(document).ready(function () {

        $('.wui-link a').click(function () {
            switch_tabs($(this));
        });

        switch_tabs($('#vol'));

    });
</script>

<script type="text/javascript">
    function switch_tabs(obj) {
        $('.tab-content').hide();
        $('.tab-content a').removeClass("selected");
        var id = obj.attr("rel");

        $('#' + id).show();
        obj.addClass("selected");
    } 
</script>

You can make function to hide all divs of content (jquery .hide() ) and then on click on li you would call jquery .show() function to show div with ceratin ID. 您可以使函数隐藏所有内容的div(jquery .hide()),然后单击li,您将调用jquery .show()函数以显示具有ceratin ID的div。 Then on clicking on another li you need to hide everything again and show only one div. 然后,在单击另一个li时,您需要再次隐藏所有内容并仅显示一个div。 Hope I helped you 希望我能帮助你

You are running the first iteration on #vol which isnt the <A> , but the containing div . 您正在#vol上运行第一次迭代,它不是<A> ,但包含div This div, #vol does not have a rel="" to complete the function. 这个div #vol没有rel =“”来完成功能。

Otherwise, it looks okay. 否则,看起来还可以。 Maybe throw in some alert()'s to make sure you are getting the correct data at some break points. 也许抛出一些alert()以确保您在某些断点处获得正确的数据。

Change: 更改:

switch_tabs($('#vol'));

To: 至:

switch_tabs($('.wui-link:first'));

and test 并测试

Change 更改

$('.wui-link a').click()

to

$('a.wui-link').click()

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

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