【小结】jQuery过滤器/筛选器

2019-06-17  本文已影响0人  音无级鹦鹉螺号szhiku

一般情况下不会单独使用,和其他基本选择器组合使用,在现有的基础上再进行筛选过滤,使得选择更加精准,因此个人认为称作过滤器好一些,主要有两个系列,一个是child系列,一个是type系列,第二个比较常用
child系列主要有以下过滤器:
:first-child
:last-child
:nth-child(n | even | odd | formula)
:nth-last-child(n | even | odd | formula)
:only-child
特点:

:first-child

例如:
$('details > p:first-child') //details标签下第一个必须是p标签才会被选择;

:last-child

例如:
$('details > p:last-child') //details标签下最后一个必须是p标签才会被选择;

:nth-child(n | even | odd | formula)

例如:
$('details > p:nth-child(2)') //details标签下第二个必须是p标签才会被选择;

:nth-last-child(n | even | odd | formula)

例如:
$('details > p:nth-last-child(2)') //details标签下倒数第二个必须为p标签才会被选择;

:only-child

例如:
$('details > p:only-child') //details标签下第一个必须只有一个子标签并且为p标签才会被选择;


type系列主要有以下过滤器:
:first-of-type
:last-of-type
:nth-of-type (n | even | odd | formula)
:nth-of-type (n | even | odd | formula)
:only-of-type
其用法与child一致
特点:


child系列与type系列的区别

上一篇 下一篇

猜你喜欢

热点阅读