jQuery的选择器

*

// 所有元素

$("*")

id

// id=”lastname”的元素

$("#lastname")

.class

// class=”intro”的所有元素

$(".intro")    

.class,.class

// class为”intro”或”demo”的所有元素

$(".intro,.demo")

element

// 所有<p>元素

$("p")

el1,el2,el3

// 所有<h1>、<div><p>元素

$("h1,div,p")

:first

// 第一个<p>元素

$("p:first")

:last

// 最后一个<p>元素

$("p:last")

:even

// 所有偶数<tr>元素
索引值从0开始,第一个元素是偶数(0)
第二个元素是奇数(1),以此类推

$("tr:even")

:odd

// 所有奇数<tr>元素
索引值从0开始,第一个元素是偶数(0)
第二个元素是奇数(1),以此类推

$("tr:odd")

:first-child

// 属于其父元素的第一个子元素的所有<p>元素

$("p:first-child")

:first-of-type

// 属于其父元素的第一个<p>元素的所有<p>元素

$("p:first-of-type")

:last-child

// 属于其父元素的最后一个子元素的所有<p>元素

$("p:last-child")

:last-of-type

// 属于其父元素的最后一个<p>元素的所有<p>元素

$("p:last-of-type")

:nth-child(n)

// 属于其父元素的第二个子元素的所有<p>元素

$("p:nth-child(2)")

:nth-last-child(n)

// 属于其父元素的第二个子元素的所有<p>元素,从最后一个子元素开始计数

$("p:nth-last-child(2)")

:nth-of-type(n)

// 属于其父元素的第二个<p>元素的所有<p>元素

$("p:nth-of-type(2)")

:nth-last-of-type(n)

// 属于其父元素的第二个<p>元素的所有<p>元素,从最后一个子元素开始计数

$("p:nth-last-of-type(2)")

:only-child

// 属于其父元素的唯一子元素的所有<p>元素

$("p:only-child")

:only-of-type

// 属于其父元素的特定类型的唯一子元素的所有<p>元素

$("p:only-of-type")

parent > child

//<div>元素的直接子元素的所有<p>元素

$("div > p")

parent descendant

// <div>元素的后代的所有<p>元素

$("div p")

element + next

// 每个<div>元素相邻的下一个<p>元素

$("div + p")

element ~ siblings

// <div>元素同级的所有<p>元素

$("div ~ p")

:eq(index)

// 列表中的第四个元素(index值从0开始)

$("ul li:eq(3)")

:gt(no)

// 列举index大于3的元素

$("ul li:gt(3)")

:lt(no)

// 列举index小于3的元素

$("ul li:lt(3)")

:not(selector)

// 所有不为空的输入元素

$("input:not(:empty)")

// 所有标题元素<h1>,<h2>...

$(":header")

:animated

// 所有动画元素

$(":animated")

:focus

// 当前具有焦点的元素

$(":focus")

:contains(text)

// 所有包含文本”Hello”的元素

$(":contains('Hello')")

:has(selector)

// 所有包含有<p>元素在其内的<div>元素

$("div:has(p)")

:empty

// 所有空元素

$(":empty")

:parent

// 匹配含有子元素或者文本的元素

$(":parent")

:hidden

// 所有隐藏的<p>元素

$("p:hidden")

:visible

// 所有可见的表格

$("table:visible")

:root

// 文档的根元素

$(":root")

:lang(language)

// 所有lang属性值为”de”的<p>元素

$("p:lang(de)")

[attribute]

// 所有带有href属性的元素

$("[href]")

[attribute=value]

// 所有带有href属性且值等于”default.htm”的元素

$("[href='default.htm']")

[attribute!=value]

// 所有带有href属性且值不等于”default.htm”的元素

$("[href!='default.htm']")

[attribute$=value]

// 所有带有href属性且值以”.jpg”结尾的元素

$("[href$='.jpg']")

[attribute|=value]

// 所有带有title属性且值等于’Tomorrow’或者以’Tomorrow’后跟连接符作为开头的字符串

$("[title|='Tomorrow']")

[attribute^=value]

// 所有带有title属性且值以”Tom”开头的元素

$("[title^='Tom']")

[attribute~=value]

// 所有带有title属性且值包含单词”hello”的元素

$("[title~='hello']")

[attribute*=value]

// 所有带有title属性且值包含字符串”hello”的元素

$("[title*='hello']")

[name=value][name2=value2]

// 带有id属性,并且name属性以man结尾的输入框

$( "input[id][name$='man']")

:input

// 所有input元素

$(":input")

:text

// 所有带有type=”text”的input元素

$(":text")

:password

// 所有带有type=”password”的input元素

$(":password")

:radio

// 所有带有type=”radio”的input元素

$(":radio")

:checkbox

// 所有带有type=”checkbox”的input元素

$(":checkbox")

:submit

// 所有带有type=”submit”的input元素

$(":submit")

:reset

// 所有带有type=”reset”的input元素

$(":reset")

:button

// 所有带有type=”button”的input元素

$(":button")

:image

// 所有带有type=”image”的input元素

$(":image")

:file

// 所有带有type=”file”的input元素

$(":file")

:enabled

// 所有启用的元素

$(":enabled")

:disabled

// 所有禁用的元素

$(":disabled")

:selected

// 所有选定的下拉列表元素

$(":selected")

:checked

// 所有选中的复选框选项

$(":checked")

:target

// 选择器将选中ID和URI中一个格式化的标识符相匹配的<p>元素

$( "p:target")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值