日期:2014-05-16 浏览次数:20316 次
<div>
<div>11111111111</div>
<div>11111111111</div>
<div>11111111111</div>
</div>
<script language="javascript" type="text/javascript">
var $res=$("div:nth-child(1)");
$res.each(function(){
$(this).css({background:"red"});
});
</script>
<div>
<div>aaa</div>
<div>bbb</div>
<div>ccc</div>
</div>
<div>
<div>ddd</div>
<div>eee</div>
<div>fff</div>
</div>
<button>div:nth-child(2)</button>
<button>div :nth-child(2)</button>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
<!--
$("button").click(function () {
var s= $(this).html();
$("div").css({background:""});
$(s).each(function(){
$(this).css({background:"red"});
});
});
//-->
</script>
<!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 src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<title>无标题文档</title>
</head>
<body>
<div>
<div style="background-color:#ddd">11111111111</div>
<div style="background-color:#333">222222222222222222222222</div>
<div style="background-color:#999">5555555555555555555555555555</div>
</div>
<script type="text/javascript">
$(function() {
/*
$("div:nth-child(1)").each(function(){
$(this).css({background:"green"});
});
*/
$('div').children().first().css('background-color', 'green');
});
</script>
</body>
</html>
<div id="o1"&