隐藏或显示特定的DIV [英] Hide or show specific DIVs

查看:113
本文介绍了隐藏或显示特定的DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个DIV.一个有一个列表,另一个有一个DIV的集合.

I have two DIV's. One has a list and the other has a collections of DIV's.

<div>
    <ul>
        <li><a>One</a></li>
        <li><a>Two</a></li>
        <li><a>Three</a></li>
    </ul>
</div>
<div>
    <div>Some content one</div>
    <div>Some content two</div>
    <div>Some content three</div>
</div>

当我单击超链接一个"时,我想显示第一个DIV(某些内容为一个)并隐藏所有其他DIV.当我单击超链接"Two"时,我想显示第二个DIV(某些内容为两个)并隐藏所有其他内容.如何使用jQuery中的数组完成此操作?任何其他方法都可以.

When I click on the hyperlink 'One', I want to show the first DIV(Some content one) and hide all the other DIVs. When I click on the hyperlink 'Two', I want to show second DIV(Some content two) and hide all the others. How can I accomplish this using arrays in jQuery? Any other method is fine too.

感谢您的时间.

推荐答案

$('li').click(function() {
    var which = $(this).index();
    $('div').find('div').hide().eq(which).show();
});

工作小提琴

这篇关于隐藏或显示特定的DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆