作者:阡蓝fliona | 来源:互联网 | 2023-01-28 19:53
web前端|js教程first-child,jQuery,选择器,出现,使用web前端-js教程易语言全局注入源码,怎么用vscode写html5,ubuntu安全设置,tomca
web前端|js教程
first-child,jQuery,选择器,出现,使用
web前端-js教程
易语言全局注入源码,怎么用vscode写html5,ubuntu 安全设置,tomcat部署文件目录在哪,Sqlite定义视图,东凤网页设计有创意,读取远程服务器上的文件,html手机端页面日期插件,前端主流框架比较,小爬虫类,php85,seo优化有什么用,网站首页模块,腾讯云网页模板,discuz文章模板,html5页面动画效果,.net人事管理系统源码,php静态博客程序lzw
jQuery中:first-child的使用问题
数据查询修改网站源码,ubuntu下安装npm,tomcat输入的日志在,爬虫 截屏,php源码搭建教程外包,runoob seolzw
用first-child可以取出每一个
代刷网总控系统源码,ubuntu启动显示dev,爬虫 输出excel格式,php中ceil,越秀seo外包lzw
之中的- 元素,用first就不行。明白?
在jQuery的子元素过滤选择器中,:first-child的使用需要注意一点,文档中说的例子是这样用的:
$("ul li:first-child").addClass("highlight");
它实现的作用是获取到所有ul下面的第一个li元素,与:first有区别。
$("ul li:first").addClass("highlight");
:first只获取一个ul中的第一个li,前提都是页面中有2个ul列表。
对于:
$("ul li:first-child").addClass("highlight");
可以使用另一种写法,效果一样,当然我觉得后者更好理解一些,因为是选择ul下的第一个子元素:
$(“ul :first-child”).addClass(“highlight”);
以上例子中的空格都需要注意。
$(function(){ //$("ul li:first-child").addClass("highlight"); //$("ul :first-child").addClass("highlight"); //和上面效果一样 注意空格 $("ul :nth-child(2n)").addClass("highlight"); //$(".one .mini:nth-child(2)").addClass("highlight"); //和下面一样效果 //$(".one :nth-child(2)").addClass("highlight"); //$(".one .mini:last-child").addClass("highlight"); //和下面一样效果 $(".one :last-child)").addClass("highlight");});