jQuery的选择器

来自jQuer强大的选择器,《jQuery in action》

 

常用的选择方式:

*

Matches any element.
EMatches all element with tag name E.
E FMatches all elements with tag name F that are descendents of E.
E>FMatches all elements with tag name F that are direct children of E.
E+FMatches all elements F immediately preceded by sibling E.
E~FMatches all elements F preceded by any sibling E.
E:has(F)Matches all elements with tag name E that have at least one descendent with tag name F.
E.CMatches all elements E with class name C. Omitting E is the same as *.C.
E#IMatches element E with id of I. Omitting E is the same as *#I.
E[A]Matches all elements E with attribute A of any value.
E[A=V]Matches all elements E with attribute A whose value is exactly V.
E[A^=V]Matches all elements E with attribute A whose value begins with V.
E[A$=V]Matches all elements E with attribute A whose value ends with V.
E[A*=V]Matches all elements E with attribute A whose value contains V.
:firstThe first match of the page. li a:first returns the first link also under a list item.
:lastThe last match of the page. li a:last returns the last link also under a list item.
:first-childThe first child element. li:first-child returns the first item of each list.
:last-childThe last child element. li:last-child returns the last item of each list.
:only-childReturns all elements that have no siblings.
:nth-child(n)The nth child element. li:nth-child(2) returns the second list item of each list.
:nth-child(even|odd)Even or odd children. li:nth-child(even) returns the even children of each list.
:nth-child(Xn+Y)The nth child element computed by the supplied formula. If Y is 0, it may be omitted. li:nth-child(3n) returns every third item, whereas li:nth-child(5n+1) returns the item after every fifth element.
:even and :oddEven and odd matching elements page-wide. li:even returns every even list item.
:eq(n)The nth matching element.
:gt(n)Matching elements after (and excluding) the nth matching element.
:lt(n)Matching elements before (and excluding) the nth matching element.
:animatedSelects elements that are currently under animated control. Chapter 5 will cover animations and effects.
:buttonSelects any button (input[type=submit], input[type=reset],input[type=button], or button).
:checkboxSelects only check box elements (input[type=checkbox]).
:checkedSelects only check boxes or radio buttons that are checked (supported by CSS).
:contains(foo)Selects only elements containing the text foo.
:disabledSelects only form elements that are disabled in the interface (supported by CSS).
:enabledSelects only form elements that are enabled in the interface (supported by CSS).
:fileSelects all file elements (input[type=file]).
:headerSelects only elements that are headers; for example: <H1>through <elements.>
:hiddenSelects only elements that are hidden.
:imageSelects form images (input[type=image]).
:inputSelects only form elements (input, select, textarea, button).
:not(filter)Negates the specified filter.
:parentSelects only elements that have children (including text), but not empty elements.
:passwordSelects only password elements (input[type=password]).
:radioSelects only radio elements (input[type=radio]).
:resetSelects reset buttons (input[type=reset] or button[type=reset]).
:selectedSelects option elements that are selected.
:submitSelects submit buttons (button[type=submit] or input[type=submit]).
:textSelects only text elements (input[type=text]).
:visibleSelects only elements that are visible.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

选择器应用示例:

ul.myList > li > a

a[href^=http://]

input[type=text]

li:has(a)

foo:not(bar:has(baz))

:checkbox:checked:enabled

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值