jQuery中:first、:firstchild、:firstoftype与:nthchild、:nthoftype有何具体区别?
- 内容介绍
- 文章标签
- 相关推荐
本文共计598个文字,预计阅读时间需要3分钟。
:first: 选择第一个出现的匹配元素: first-child: 选择限制条件中的第一个元素,并且必须和前面的标签一致: first-of-type: 选择在所有限制条件中,第一个出现的指定类型的元素,该元素可以与前面的标签不一致
:first:选择第一个出现符合的元素:first-child:选择限制条件中的第一个元素,并且必须和冒号前面的标签一致:first-of-type:选择所有限制条件下的第一个冒号前面的标签元素,此标签可以不是第一个测试:first代码:amp;amp;lt;bodyamp;amp;gt;amp;amp;lt;aamp;amp;gt;amp;amp:first:选择第一个出现符合的元素
:first-child:选择限制条件中的第一个元素,并且必须和冒号前面的标签一致
:first-of-type:选择所有限制条件下的第一个冒号前面的标签元素,此标签可以不是第一个
测试:first代码:
1
2
3
Hello1Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:
测试:first-child代码:
1
2
3
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:
测试:first-of-type代码:
1
2
3
Hello1Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:
怎么样,很好理解吧,研究了好半天的呀!
下面是补充的:nth-child()和:nth-of-type()区别
:nth-child:是选择父元素下的第几个元素,不分标签类别,计数从1开始
:nth-of-type:是选择父元素下的同类型元素的第几个元素。区分标签类别,计数从1开始
测试:nth-child()代码:
1
2
3
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:
测试:nth-of-type()代码:
1
2
3
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:
本文共计598个文字,预计阅读时间需要3分钟。
:first: 选择第一个出现的匹配元素: first-child: 选择限制条件中的第一个元素,并且必须和前面的标签一致: first-of-type: 选择在所有限制条件中,第一个出现的指定类型的元素,该元素可以与前面的标签不一致
:first:选择第一个出现符合的元素:first-child:选择限制条件中的第一个元素,并且必须和冒号前面的标签一致:first-of-type:选择所有限制条件下的第一个冒号前面的标签元素,此标签可以不是第一个测试:first代码:amp;amp;lt;bodyamp;amp;gt;amp;amp;lt;aamp;amp;gt;amp;amp:first:选择第一个出现符合的元素
:first-child:选择限制条件中的第一个元素,并且必须和冒号前面的标签一致
:first-of-type:选择所有限制条件下的第一个冒号前面的标签元素,此标签可以不是第一个
测试:first代码:
1
2
3
Hello1Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:
测试:first-child代码:
1
2
3
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:
测试:first-of-type代码:
1
2
3
Hello1Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:
怎么样,很好理解吧,研究了好半天的呀!
下面是补充的:nth-child()和:nth-of-type()区别
:nth-child:是选择父元素下的第几个元素,不分标签类别,计数从1开始
:nth-of-type:是选择父元素下的同类型元素的第几个元素。区分标签类别,计数从1开始
测试:nth-child()代码:
1
2
3
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:
测试:nth-of-type()代码:
1
2
3
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
其中结果为:

