[JQ权威指南]第四天:使用jQuery子元素过滤选择器
2015-06-16 10:04
656 查看
<!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" /> <head> <title>使用jQuery子元素过滤选择器</title> <script language="javascript" type="text/javascript" src="jquery-2.1.4.js"></script> <style type="text/css"> body { font-size: 12px; text-align: center } ul { width: 241px; list-style-type: none; padding: 0px } ul li { height: 23px; width: 60px; line-height: 23px; float: left; border-top: solid 1px #eee; border-bottom: solid 1px #eee; margin-bottom: 5px } .GetFocus { width: 58px; border: solid 1px #666; background-color: #eee } </style> <script type="text/javascript"> // $(function(){ //增加每个父元素下的第2个子元素类别 // $("li:nth-child(2)").addClass("GetFocus"); // }) // $(function(){ //增加每个父元素下的第一个子元素类别 // $("li:first-child").addClass("GetFocus"); // }) // $(function(){ //增加每个父元素下的最后一个子元素类别 // $("li:last-child").addClass("GetFocus"); // }) $(function(){ //增加每个父元素下只有一个子元素类别 $("li:only-child").addClass("GetFocus"); }) </script> </head> <body> <ul> <li>Item 1-0</li> <li>Item 1-1</li> <li>Item 1-2</li> <li>Item 1-3</li> </ul> <ul> <li>Item 2-0</li> <li>Item 2-1</li> <li>Item 2-2</li> <li>Item 2-3</li> </ul> <ul> <li>Item 3-0</li> </ul> </body> </html>
相关文章推荐
- Dojo实现跨源(CROS)请求
- 关于jquery中each循环篇
- jquery自定义控件验证篇
- jQuery Mobile Data 属性
- jquerymobile标签-属性手册
- jquery插件splitScren实现页面分屏切换模板特效
- jQuery封装的tab选项卡插件分享
- jQuery插件zepto.js简单实现tab切换
- 动态加载jQuery的方法
- jQuery 遍历 json 方法大全
- jQuery.data() 与 jQuery(elem).data()源码解读
- JQuery工具函数汇总
- jquery知识
- jquery 初步(八) 表单对象选择器
- Jquery ajax传递复杂参数给WebService
- jquery 初步(七) 子元素过滤选择器
- 【jQuery】鼠标接触按钮后改变图片
- jQuery Tap插件
- jquery如何判断checkbox(复选框)是否被选中
- jQuery实战:创建元素包装集,选择将被操作的元素