dongliang2005 2011-04-25 09:14
浏览 31
已采纳

jQuery或PHP - 如果启用/禁用了另一个DIV,则显示/隐藏DIV或LI

I have another question, not sure if this would be accomplished via PHP or jQuery, so I am posting it in both sections.

Basically what I want is this:

I have several DIVs on a page, including 4 divs entitled "Spring", "Summer", "Autumn" and "Winter".

I have another DIV that is called "Menu". In the menu, you can toggle each of the four season DIVs via jQuery. There are also several list items, for example "Ice Rinks" and "Ice Cream Stores". "Ice Rinks" would only be available when "Winter" is selected, and "Ice Cream Stores" when Summer is selected.

What I would like to do, preferably via jQuery, is HIDE "Ice Cream Stores" from the menu when the "Winter" DIV is enabled, or HIDE "Ice Rinks" when the "Summer" DIV is enabled.

Basically, I need a way to either selectivly, or dynamically (perhaps via a class on the list items) assign the menu items to one of the 4 Season DIVS, and then hide those items from the Menu when the associated Season DIV is toggled off.

Is this possible, and if so, does anyone have any code examples of how this would be accomplished?

Thanks Zach

  • 写回答

1条回答 默认 最新

  • dongshai1944 2011-04-25 09:41
    关注

    It's possible. You can do like this

    HTML:

    <div id="spring" class="menubtn">Spring</div>
    <div id="summer" class="menubtn">Summer</div>
    <div id="autumn" class="menubtn">Autumn</div>
    <div id="winter" class="menubtn">Winter</div>
    <ul id="itemlist">
        <li class="winter">Ice Rinks</li>
        <li class="summer">Ice Cream Stores</li>
    </ul>  
    

    Javascript:

    $(document).ready(function(){
        $('.menubtn').click(function(){
            // Handle Menu
            $('.menubtn').removeClass('active')
            $(this).addClass('active');
    
            // Handle item list. This is what you want to do 
            $('#itemlist li').hide();
            $('#itemlist li.' + $(this).attr('id')).show();
        });
    });
    

    You can see the demo here: http://jsfiddle.net/ynhat/Cgeus/3/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档