<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<style type="text/css">
#our_case{
margin-top:15px;
margin-left:45px;
width:454px;
height:36px;
margin-right:75px;
float:right;
}#mobile_web{
float:left;
margin-left:1px;
width:80px;
height:20px;
border:1px solid #DBDFE5;
background:#DBDFE5;
padding-top:5px;
text-align:center;
cursor: pointer;
}
#mobile_app{
float:left;
margin-left:1px;
width:80px;
height:20px;
border:1px solid #DBDFE5;
background:#DBDFE5;
padding-top:5px;
text-align:center;
cursor: pointer;
}
#ebusiness{
float:left;
margin-left:1px;
width:80px;
height:20px;
border:1px solid #DBDFE5;
background:#DBDFE5;
padding-top:5px;
text-align:center;
cursor: pointer;
}
.show{
margin-top:35px;
margin-left:45px;
width:254px;
margin-right:15px;
float:right;
border:1px solid red;
}
.show ul{
list-style:none;
}
.show ul{
display:none;
float:left;
}
.show .block{
display:block;
float:left;
}
</style>
</head>
<body>
<div id="our_case">
<div id="mobile_web"> 手机网站</div>
<div id="mobile_app"> 移动应用</div>
<div id="ebusiness"> 电子商务</div>
</div>
<div class="show" id="show0"> <ul class="block">
<li>测试1</li>
<li>测试1</li>
<li>测试1</li>
</ul> <ul>
<li>测试2</li>
<li>测试2</li>
<li>测试2</li>
</ul> <ul>
<li>测试3</li>
<li>测试3</li>
<li>测试3</li>
</ul></body>
</html>
比如我点击手机网站的时候只显示测试1,然后更改背景颜色,点击移动应用的时候只显示测试2,再更改背景颜色。用jquery怎么实现切换啊。小弟刚入门,求大侠们指点!!jQueryWeb

解决方案 »

  1.   


    $("div").each(function(index,item){
       $(this).bind("click",function(){
            // 获得div的id 比如:mobile_web
            // 查找ul的id为mobile_web的ul
            $("#show0").children("ul[id='mobile_web']").toggleclass("自己定义的样式");
    })
    })
      

  2.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <title>test</title>
    <style type="text/css">
    #our_case{
    margin-top:15px;
    margin-left:45px;
    width:454px;
    height:36px;
    margin-right:75px;
    float:right;
    }#mobile_web{
    float:left;
    margin-left:1px;
    width:80px;
    height:20px;
    border:1px solid #DBDFE5;
    background:#DBDFE5;
    padding-top:5px;
    text-align:center;
    cursor: pointer;
    }
    #mobile_app{
    float:left;
    margin-left:1px;
    width:80px;
    height:20px;
    border:1px solid #DBDFE5;
    background:#DBDFE5;
    padding-top:5px;
    text-align:center;
    cursor: pointer;
    }
    #ebusiness{
    float:left;
    margin-left:1px;
    width:80px;
    height:20px;
    border:1px solid #DBDFE5;
    background:#DBDFE5;
    padding-top:5px;
    text-align:center;
    cursor: pointer;
    }
    .show{
    margin-top:35px;
    margin-left:45px;
    width:254px;
    margin-right:15px;
    float:right;
    border:1px solid red;
    }
    .show ul{
    list-style:none;
    }
    .show ul{
    display:none;
    float:left;
    }
    .show .block{
    display:block;
    float:left;
    }
    </style></head>
    <body>
    <div id="our_case">
    <div id="mobile_web"> 手机网站</div>
    <div id="mobile_app"> 移动应用</div>
    <div id="ebusiness"> 电子商务</div>
    </div>
    <div class="show" id="show0"><ul class="block">
    <li>测试1</li>
    <li>测试1</li>
    <li>测试1</li>
    </ul><ul>
    <li>测试2</li>
    <li>测试2</li>
    <li>测试2</li>
    </ul><ul>
    <li>测试3</li>
    <li>测试3</li>
    <li>测试3</li>
    </ul>
    </div><script>
        $("#our_case").find("div").bind("click", function () {
            var index = $("#our_case").find("div").index(this);        $("#our_case").find("div").each(function () {
                if ($("#our_case").find("div").index(this) == index) {
                    $(this).css("background", "red");
                } else {
                    $(this).css("background", "#DBDFE5");
                }
            });        $("#show0").find("ul").each(function () {            if ($("#show0").find("ul").index(this) == index) {
                    $(this).addClass("block");
                } else {
                    $(this).removeClass("block");
                }
            });    })
    </script>
    </body>
    </html>