非常教程

jQuery参考手册

jQuery 选择器

jQuery 选择器

jQuery 选择器


jQuery 选择器

请使用我们的 jQuery 选择器检测器 来演示不同的选择器。

选择器 实例 选取
* $("*") 所有元素
#id $("#lastname") id="lastname" 的元素
.class $(".intro") class="intro" 的所有元素
.class,.class $(".intro,.demo") class 为 "intro" 或 "demo" 的所有元素
element $("p") 所有 <p> 元素
el1,el2,el3 $("h1,div,p") 所有 <h1>、<div> 和 <p> 元素
:first $("p:first") 第一个 <p> 元素
:last $("p:last") 最后一个 <p> 元素
:even $("tr:even") 所有偶数 <tr> 元素,索引值从 0 开始,第一个元素是偶数 (0),第二个元素是奇数 (1),以此类推。
:odd $("tr:odd") 所有奇数 <tr> 元素,索引值从 0 开始,第一个元素是偶数 (0),第二个元素是奇数 (1),以此类推。
:first-child $("p:first-child") 属于其父元素的第一个子元素的所有 <p> 元素
:first-of-type $("p:first-of-type") 属于其父元素的第一个 <p> 元素的所有 <p> 元素
:last-child $("p:last-child") 属于其父元素的最后一个子元素的所有 <p> 元素
:last-of-type $("p:last-of-type") 属于其父元素的最后一个 <p> 元素的所有 <p> 元素
:nth-child(n) $("p:nth-child(2)") 属于其父元素的第二个子元素的所有 <p> 元素
:nth-last-child(n) $("p:nth-last-child(2)") 属于其父元素的第二个子元素的所有 <p> 元素,从最后一个子元素开始计数
:nth-of-type(n) $("p:nth-of-type(2)") 属于其父元素的第二个 <p> 元素的所有 <p> 元素
:nth-last-of-type(n) $("p:nth-last-of-type(2)") 属于其父元素的第二个 <p> 元素的所有 <p> 元素,从最后一个子元素开始计数
:only-child $("p:only-child") 属于其父元素的唯一子元素的所有 <p> 元素
:only-of-type $("p:only-of-type") 属于其父元素的特定类型的唯一子元素的所有 <p> 元素
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) $("ul li:eq(3)") 列表中的第四个元素(index 值从 0 开始)
:gt(no) $("ul li:gt(3)") 列举 index 大于 3 的元素
:lt(no) $("ul li:lt(3)") 列举 index 小于 3 的元素
:not(selector) $("input:not(:empty)") 所有不为空的输入元素
:header $(":header") 所有标题元素 <h1>, <h2> ...
:animated $(":animated") 所有动画元素
:focus $(":focus") 当前具有焦点的元素
:contains(text) $(":contains('Hello')") 所有包含文本 "Hello" 的元素
:has(selector) $("div:has(p)") 所有包含有 <p> 元素在其内的 <div> 元素
:empty $(":empty") 所有空元素
:parent $(":parent") 匹配所有含有子元素或者文本的父元素。
:hidden $("p:hidden") 所有隐藏的 <p> 元素
:visible $("table:visible") 所有可见的表格
:root $(":root") 文档的根元素
:lang(language) $("p:lang(de)") 所有 lang 属性值为 "de" 的 <p> 元素
     
[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']") 所有带有 title 属性且值等于 'Tomorrow' 或者以 'Tomorrow' 后跟连接符作为开头的字符串
[attribute^=value] $("[title^='Tom']") 所有带有 title 属性且值以 "Tom" 开头的元素
[attribute~=value] $("[title~='hello']") 所有带有 title 属性且值包含单词 "hello" 的元素
[attribute*=value] $("[title*='hello']") 所有带有 title 属性且值包含字符串 "hello" 的元素
[name=value][name2=value2] $( "input[id][name$='man']" ) 带有 id 属性,并且 name 属性以 man 结尾的输入框
     
:input $(":input") 所有 input 元素
:text $(":text") 所有带有 type="text" 的 input 元素
:password $(":password") 所有带有 type="password" 的 input 元素
:radio $(":radio") 所有带有 type="radio" 的 input 元素
:checkbox $(":checkbox") 所有带有 type="checkbox" 的 input 元素
:submit $(":submit") 所有带有 type="submit" 的 input 元素
:reset $(":reset") 所有带有 type="reset" 的 input 元素
:button $(":button") 所有带有 type="button" 的 input 元素
:image $(":image") 所有带有 type="image" 的 input 元素
:file $(":file") 所有带有 type="file" 的 input 元素
:enabled $(":enabled") 所有启用的元素
:disabled $(":disabled") 所有禁用的元素
:selected $(":selected") 所有选定的下拉列表元素
:checked $(":checked") 所有选中的复选框选项
.selector $(selector).selector 在jQuery 1.7中已经不被赞成使用。返回传给jQuery()的原始选择器
:target $( "p:target" ) 选择器将选中ID和URI中一个格式化的标识符相匹配的<p>元素

jQuery 选择器

jQuery目录

1.jQuery 教程
2.jQuery 简介
3.jQuery 安装
4.jQuery 语法
5.jQuery 选择器
6.jQuery 效果 – 隐藏和显示
7.jQuery 事件
8.jQuery 效果 – 滑动
9.jQuery 效果 – 淡入淡出
10.jQuery 链
11.jQuery Callback 方法
12.jQuery 效果 – 停止动画
13.jQuery 效果 – 动画
14.jQuery 遍历 – 后代
15.jQuery 遍历 – 祖先
16.jQuery 遍历
17.jQuery 尺寸
18.jQuery css() 方法
19.jQuery 获取并设置 CSS 类
20.jQuery 删除元素
21.jQuery 添加元素
22.jQuery 设置内容和属性
23.jQuery 获取内容和属性
24.jQuery 实例
25.jQuery noConflict() 方法
26.jQuery – AJAX get() 和 post() 方法
27.jQuery – AJAX load() 方法
28.jQuery AJAX 简介
29.jQuery 遍历 – 过滤
30.jQuery 遍历 – 同胞(siblings)
31.jQuery :even 选择器
32.jQuery :last 选择器
33.jQuery :first 选择器
34.jQuery 多个元素选择器
35.jQuery element 选择器
36.jQuery 多个类选择器
37.jQuery .class 选择器
38.jQuery #id 选择器
39.jQuery * 选择器
40.jQuery :only-child 选择器
41.jQuery :nth-last-of-type() 选择器
42.jQuery :nth-of-type() 选择器
43.jQuery :nth-last-child() 选择器
44.jQuery :nth-child() 选择器
45.jQuery :last-of-type 选择器
46.jQuery :last-child 选择器
47.jQuery :first-of-type 选择器
48.jQuery :first-child 选择器
49.jQuery :odd 选择器
50.jQuery :header 选择器
51.jQuery :not() 选择器
52.jQuery :lt() 选择器
53.jQuery :gt() 选择器
54.jQuery :eq() 选择器
55.jQuery element ~ siblings 选择器
56.jQuery element + next 选择器
57.jQuery 父后代选择器
58.jQuery parent > child 选择器
59.jQuery :only-of-type 选择器
60.jQuery :lang() 选择器
61.jQuery :root 选择器
62.jQuery :visible 选择器
63.jQuery :hidden 选择器
64.jQuery :parent 选择器
65.jQuery :empty 选择器
66.jQuery :has() 选择器
67.jQuery :contains() 选择器
68.jQuery :focus 选择器
69.jQuery :animated 选择器
70.jQuery :input 选择器
71.jQuery [attribute*=value] 选择器
72.jQuery [attribute~=value] 选择器
73.jQuery [attribute^=value] 选择器
74.jQuery [attribute|=value] 选择器
75.jQuery [attribute$=value] 选择器
76.jQuery [attribute!=value] 选择器
77.jQuery [attribute=value] 选择器
78.jQuery [attribute] 选择器
79.jQuery :image 选择器
80.jQuery :button 选择器
81.jQuery :reset 选择器
82.jQuery :submit 选择器
83.jQuery :checkbox 选择器
84.jQuery :radio 选择器
85.jQuery :password 选择器
86.jQuery :text 选择器
87.jQuery dblclick() 方法
88.jQuery click() 方法
89.jQuery change() 方法
90.jQuery blur() 方法
91.jQuery bind() 方法
92.jQuery :checked 选择器
93.jQuery :selected 选择器
94.jQuery :disabled 选择器
95.jQuery :enabled 选择器
96.jQuery :file 选择器
97.jQuery event.namespace 属性
98.jQuery event.isPropagationStopped() 方法
99.jQuery event.isImmediatePropagationStopped() 方法
100.jQuery event.isDefaultPrevented() 方法