打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
子元素过滤器练习页

<!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>子元素过滤器</title>
<script type="text/javascript" src="../jquery-1.4.1.js"></script>
<script type="text/javascript">
//选择所有div下边的第一个子元素

$(function(){
 $('#b1').click(function(){
  
  $('div:nth-child(3)').css('background','#ccc')
  
  })
 
 
 })
//选取所有div下边的第一个子元素,相当于 div:nth-child(1)
$(function(){
 $('#b2').click(function(){
  
  $('div:first-child').css('background','#ccc')
  
  })
 }) 
 
 //选取所有div下边最后子元素
$(function(){
 $('#b3').click(function(){
  
  $('div:last-child').css('background','#ccc')
  })
  })
//选取有唯一子元素的子元素  
$(function(){
 $('#b4').click(function(){
  
  $('div:only-child').css('background','#ccc')
  })
  })  
  
  
</script>
</head>

<body>
<div id="div1"  style="width:200px; height:100px; margin:10px; border:1px solid #F00">这是第一个div
  <div style=" width:150px; height:50px;border:1px solid #F00;margin:10px">第一个div中的div</div>
</div>

<div id="div2"  style="width:200px; height:200px; margin:10px; border:1px solid #F00">这是第er个div
  <div style=" width:150px; height:50px;border:1px solid #F00;margin:10px">第er个div中的div</div>
   <div style=" width:150px; height:50px;border:1px solid #F00;margin:10px">第er个div中的div</div>
  
</div>


<div id="div3"  style="width:200px; height:220px; margin:10px; border:1px solid #F00">这是第san个div
  <div style=" width:150px; height:50px;border:1px solid #F00;margin:10px">第san个div中的div</div>
   <div style=" width:150px; height:50px;border:1px solid #F00;margin:10px">第san个div中的div</div>
   <div style=" width:150px; height:50px;border:1px solid #F00;margin:10px">第san个div中的div</div>
</div>

<input type="button" value="测试"id="b1"/><input type="button" value="测试"id="b2"/><input type="button"value="测试" id="b3"/><input type="button"value="测试" id="b4"/>


</body>
</html>

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
纯代码打造圆角边框
漫谈CSS和页面布局.
DIV+CSS圆角边框 - 前端LOVER - 博客园
【网站工具】—工具大全
div+css表格布局
兼容多浏览器顶端浮动导航效果
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服