返回介绍

phpQuery 选择器

发布于 2021-04-06 13:23:43 字数 9017 浏览 1230 评论 0 收藏 0

下面选择器规则完全适用于QueryList 。


Selectors are the heart of jQuery-like interface. Most of CSS Level 3 syntax is implemented (in state same as in jQuery).

Example

pq(".class ul > li[rel='foo']:first:has(a)")->appendTo('.append-target-wrapper div')->...

Basics

  • #id Matches a single element with the given id attribute.
  • element Matches all elements with the given name.
  • .class Matches all elements with the given class.
  • * Matches all elements.
  • selector1, selector2, selectorN Matches the combined results of all the specified selectors.

Hierarchy

  • ancestor descendant Matches all descendant elements specified by "descendant" of elements specified by "ancestor".
  • parent > child Matches all child elements specified by "child" of elements specified by "parent".
  • prev + next Matches all next elements specified by "next" that are next to elements specified by "prev".
  • prev ~ siblings Matches all sibling elements after the "prev" element that match the filtering "siblings" selector.

Basic Filters

  • :first Matches the first selected element.
  • :last Matches the last selected element.
  • :not(selector) Filters out all elements matching the given selector.
  • :even Matches even elements, zero-indexed.
  • :odd Matches odd elements, zero-indexed.
  • :eq(index) Matches a single element by its index.
  • :gt(index) Matches all elements with an index above the given one.
  • :lt(index) Matches all elements with an index below the given one.
  • :header Matches all elements that are headers, like h1, h2, h3 and so on.
  • :animated Matches all elements that are currently being animated.

Content Filters

  • :contains(text) Matches elements which contain the given text.
  • :empty Matches all elements that have no children (including text nodes).
  • :has(selector) Matches elements which contain at least one element that matches the specified selector.
  • :parent Matches all elements that are parents - they have child elements, including text.

Visibility Filters

none

Attribute Filters

  • [attribute] Matches elements that have the specified attribute.
  • [attribute=value] Matches elements that have the specified attribute with a certain value.
  • [attribute!=value] Matches elements that don't have the specified attribute with a certain value.
  • [attribute^=value] Matches elements that have the specified attribute and it starts with a certain value.
  • [attribute$=value] Matches elements that have the specified attribute and it ends with a certain value.
  • [attribute*=value] Matches elements that have the specified attribute and it contains a certain value.
  • [selector1selector2selectorN] Matches elements that have the specified attribute and it contains a certain value.

Child Filters

  • :nth-child(index/even/odd/equation) Matches all elements that are the nth-child of their parent or that are the parent's even or odd children.
  • :first-child Matches all elements that are the first child of their parent.
  • :last-child Matches all elements that are the last child of their parent.
  • :only-child Matches all elements that are the only child of their parent.

Forms

  • :input Matches all input, textarea, select and button elements.
  • :text Matches all input elements of type text.
  • :password Matches all input elements of type password.
  • :radio Matches all input elements of type radio.
  • :checkbox Matches all input elements of type checkbox.
  • :submit Matches all input elements of type submit.
  • :image Matches all input elements of type image.
  • :reset Matches all input elements of type reset.
  • :button Matches all button elements and input elements of type button.
  • :file Matches all input elements of type file.
  • :hidden Matches all elements that are hidden, or input elements of type "hidden".

Form Filters

  • :enabled Matches all elements that are enabled.
  • :disabled Matches all elements that are disabled.
  • :checked Matches all elements that are checked.
  • :selected Matches all elements that are selected.

Read more at Selectors section on jQuery Documentation Site.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文