t-6. 点解切换div内容

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        *{margin:0pxpadding:0px;}
        atext-decoration:none; }  ul{list-style:none;}
        .shop_all{width:300pxheight:300pxoverflowhidden;}
        .shop_all_a{width:300pxheight:300pxbackground:pink;}
        .list_shop{width:1000pxoverflowhiddenmargin:auto;}
        .list_shop p{width:200pxheight:30pxline-height:30px;}
        .shop_click{width:500pxoverflowhidden;}
        .shop_click li{width:100pxheight:40pxborder:1px solid redmargin:0px 10pxtext-align:centerline-height:40pxfloat:leftcursor:pointer;}
        .red{background:redcolor:#fff;}
    </style>
</head>
<body>


<ul class="shop_click">
        <li class="red">A款</li>
        <li>B款</li>
        <li>c</li>
</ul>


<div class="shop_all">
    <div class="shop_all_a" style="display:block;">
        aaaaaa
    </div>

    <div class="shop_all_a" style="display:none;">
        bbbbbb
    </div>
    <div class="shop_all_a" style="display:none;">
        cccccc
    </div>
</div>
 
    <script src="jquery.js"></script>
    <script>
   
        $('.shop_click li').click(function(){
           $(this).addClass('red').siblings().removeClass('red');
           //找到“red”类  找到每个div的所有同辈元素  从匹配的元素中删除 'red' 类
           $('.shop_all_a').eq($(this).index()).show().siblings().hide(); 
           //获取这个匹配的元素 显示它  同类的元素隐藏//
       })
</script>
 
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/stone5/p/9062524.html
今日推荐