jquery 遍历某个div 下的所有div怎么写
2个回答
展开全部
<!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=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<title>无标题文档</title>
<script>
$(function(){
$('#mydiv div').each(function(i){
$(this).css({'height':'30px','background-color' : '#ddd'});
if(i==3)//如果遍历到第四个时候
{$(this).css({'height':'30px','background-color' : 'yellow'});}
})
})
</script>
</head>
<body>
<div id="mydiv" style="width:200px;">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<title>无标题文档</title>
<script>
$(function(){
$('#mydiv div').each(function(i){
$(this).css({'height':'30px','background-color' : '#ddd'});
if(i==3)//如果遍历到第四个时候
{$(this).css({'height':'30px','background-color' : 'yellow'});}
})
})
</script>
</head>
<body>
<div id="mydiv" style="width:200px;">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询