<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>jquery获取指定div 所有div元素</title>
<script type= "text/网页特效" src= "jquery-1.2.6.js"> </script> <script type= "text/javascript"> $(function(){ $("#show").click(function(){ var hvalue=$("#hv").val(); hvalue=hvalue-1; $("div.list div:eq("+hvalue+")").show().siblings().hide(); }); }) </script> <style type="text/css教程"> .list div {height:100;width:100;color:red;background:blue;margin:5;} </style>
</head>
<body>
<div class="list">
<div>div1 </div>
<div>div2 </div>
<div>div3 </div>
<div>div4 </div>
</div>
我如何获取 class =list 下面的所有div
然后根据不同索引来show 和hide
<script>
$(function () {
$("div.list").css("display", "none");//or $("div.list").hide();
show(2);//显示第二个
$("#baobiao-list ul li:eq(0) a").click(function(){
show(1);
});
$("#baobiao-list ul li:eq(1) a").click(function(){
show(2);
});
});
function show(index) {
$("div.list div:eq(" + (index + 1) + ")").show();
}
</script>
</body>
</html>