jquery获取 一个DIV下的所有DIV

ILOVE_ASPNET 2010-09-25 11:00:07
<div class="list">
<div>div1 </div>
<div>div2 </div>
<div>div3 </div>
<div>div4 </div>
</div>

我如何获取 class =list 下面的所有DIV
然后根据不同索引来show 和hide

例如我有个涵数传进来的索引是 2 那么则显示DIV2 内容,其它 隐藏掉,
我的心路是先获取下面的所有DIV, 就是这个不会取, 然后做循环来判断索引, 求高人指点..
...全文
3241 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
君黑鲩 2010-10-16
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 fymxj 的回复:]
JScript code

$(".list div").each(function(){
$(this).hide();
}).end().eq(2).show();//索引为2的话是第三个DIV
///或者end()去掉换成
$(".list div").eq(2).show();
[/Quote]

这个简单明了
fymxj 2010-09-26
  • 打赏
  • 举报
回复

$(".list div").each(function(){
$(this).hide();
}).end().eq(2).show();//索引为2的话是第三个DIV
///或者end()去掉换成
$(".list div").eq(2).show();

hawk98 2010-09-26
  • 打赏
  • 举报
回复

$(".list").childen("div")//取下面所有div
wishifef 2010-09-26
  • 打赏
  • 举报
回复

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type= "text/javascript" 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>海上生明月,</div>
<div>天涯共此时。</div>
<div>情人怨遥夜,</div>
<div>竟夕起相思。</div>
</div>
<input type="text" id="hv"/>
<input type="button" id="show" value="ShowDIV"/>
</BODY>
</HTML>
ILOVE_ASPNET 2010-09-25
  • 打赏
  • 举报
回复
不行,贴上全码
//注册相关事件
$(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();
}



hoojo 2010-09-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ibm_hoojo 的回复:]

CSS code
$(function () {
$("div.list").css("display", "none");//or $("div.list").hide();
show(2);//显示第二个
});
function show(index) {
$("div.list div:eq(" + (index + 1) + ")").show();
}……
[/Quote]
代码中的$("div.list").css("display", "none");//or $("div.list").hide();就是隐藏
lqc851011 2010-09-25
  • 打赏
  • 举报
回复
$(document).ready((function () {
var i = 0;
$("div.list").each(function(this) {
i++;
if(i==2)
$(this).css('display','');
else
$(this).css('display','none');
});
});
ILOVE_ASPNET 2010-09-25
  • 打赏
  • 举报
回复
是不是要个循环,然后判断索引,如果对的就显示,不对就隐藏?
ILOVE_ASPNET 2010-09-25
  • 打赏
  • 举报
回复
那其它的隐藏呢?
hoojo 2010-09-25
  • 打赏
  • 举报
回复
$(function () {
$("div.list").css("display", "none");//or $("div.list").hide();
show(2);//显示第二个
});
function show(index) {
$("div.list div:eq(" + (index + 1) + ")").show();
}

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧