JQuery选择器有哪几种

js教程评论473 views阅读模式

选择器

实例

解释

基本选择器

*

$(*)

选取所有元素

#id

$(“#a”)

选取id=a的元素

.class

$(“.b”)

选取class=b的元素

element

$(“p”)

所有<p>元素

.class.class

$(“.a.b”)

选取所有class=a且class=b的元素

基本过滤选择器

:first

$(“p:first”)

选取第一个p元素

:last

$(“p:last”)

选取最后一个p元素

:odd

$(“p:odd”)

选取所有奇数位上的p元素

:even

$(“p:even”)

选取所有偶数位上的p元素

:ep(n)

$(“p:eq(n)”)

选取第n位p元素(index从0开始)

:gt(n)

$(“li:gt(n)”)

选取第n位之前的所有li元素(不包含第n位)

:lt(n)

$(“li:lt(n)”)

选取第n位之后的所有li元素(不包含第n位)

:root

$(“p:root”)

选取p的根元素(不写标签时代表选取全局的根元素)

:header()

$(“p:header)

选取P标签里的所有标题(不写标签时代表选取全局的标题)

:lang

$(“p:lang(language)”)

给P标签选取指定的语言(不写标签时代表选取全局的标题)

:not

$(“li:not(.active)”)

选取除了.active以外的元素

:hidden

$(“p:hidden”)

隐藏所有P标签

:visible

$(“p:visible”)

显示所有p标签

:target

$(“:target”)

选取所有目标状态的元素

:anmated

$(“p:anmated”)

获取正在运行的动画

子元素过滤器

:first-child

$(“p p:first-last”)

选取p里第一个标签为P的子元素

:last-child

$(“p p:last-child”)

选取p里最后一个为标签p的子元素(不限位置)

:first-of-type

$(“p p:first-of-type”)

获取p里出现的第一个p标签(不限位置)

:last-of-type

$(“p p:last-of-type”)

获取p里最后出现的p标签(不限位置)

:nth-child(n)

$(“p p:nth-child(2)”)

获取p里第二个p标签(下标从1开始)

:nth-of-type(n)

$(“p p:nth-of-type(2)”)

获取p里第二个出现的p标签(下标从0开始)

:nth-last-of-type(n)

$(“p p:nth-last-of-type(n)”)

获取p里倒数第几个出现的p标签

:only-child

$(“p p:only-child”)

获取p里唯一一个子元素p

:only-of-type

$(“p p:only-of-type”)

获取同辈p里唯一一个标签为p的标签

:only-of-type(even/odd)

$(“p p:only-of-type(even/odd)”)

获取p里所有为奇数或偶数的P标签(下标从1开始)

内容过滤器

:contains()

$(“p:contains(123)”)

获取p标签里所有包含“123”的标签

:empty

$(“p:empty”)

获取p标签里没有内容的所有元素(空格也算内容)

:has()

$(“p:has(P)”)

获取所有含有p标签的p

:parent

$(“p:parent”)

获取所有元素中柚子元素的p(包括文本节点)

表单选择器

:text

$(“:text”)

选取所有type为text的字段或type没有属性的

:password

$(“:password”)

选择所有type为password的

:reset

$(“:reset”)

选择所有type为reset(重置)的

:button

$(“:button”)

选择所有type为button(按钮)的

:checkbox

$(“:checkbox”)

选择所有type为checkbox(多选)的

:radio

$(“:radio”)

选择所有type为radio(单选)的

:file

$(“:file”)

选择所有上传域

:image

$(“:image”)

选择所有图像按钮

:input

$(“:input”)

选取所有input、textarea、select、button元素

:enabled

$(“:enabled”)

选取所有可用的input

:disabled

$(“:disabled”)

选择所有不可用的input

:select

$(“:select”)

被选中状态的option元素

:checked

$(“:checked”)

被选中状态的input元素(有checked的)

:focus

$(“:focus”)

选取页面进去就有焦点的input

以上就是JQuery选择器有哪几种的详细内容,更多请关注php教程其它相关文章!

企鹅博客
  • 本文由 发表于 2019年9月8日 18:14:56
  • 转载请务必保留本文链接:https://www.qieseo.com/393023.html

发表评论