导读:jQuery选择器分为:基本选择器、层次选择器、过滤选择器和表单选择器四大类。
基本选择器
1-1 基本选择器
选择器 | 功能 | 返回值 |
---|
#id | id选择器 | 单个元素 |
element | 元素选择器 | 元素集合 |
.class | 类选择器 | 元素集合 |
* | 匹配所有元素 | 元素集合 |
selector1,selector2 | 将每一个选择器匹配到的元素合并后一起返回 | 元素集合 |
层次选择器
2-1 层次选择器
选择器 | 功能 | 返回值 |
---|
ancestor descendant | 根据祖先元素匹配所有后代元素 | 元素集合 |
parent > child | 匹配子元素 | 元素集合 |
parent + next | 匹配下一个兄弟元素 | 元素集合(parent可有多个 |
prev ~ siblings | 匹配prev之后的所有兄弟元素 | 元素集合 |
注:siblings()方法与选择器prev~siblings的区别

过滤选择器
3-1 简单过滤选择器
选择器 | 功能 | 返回值 |
---|
first() 或 : first | 获取第一个元素 | 单个元素 |
last() 或 : last | 最后一个 | 单个元素 |
:even | 索引值为偶数的元素,索引号从0开始 | 元素集合 |
:odd | 奇数 | 元素集合 |
:gt(index) | 大于索引值的元素,索引号从0开始 | 元素集合 |
:lt(index) | 小于 | 元素集合 |
:not(selector) | 除给定选择器外的所有元素 | 元素集合 |
:eq(index) | 指定索引值的元素 | 单个元素 |
:header | 所有标题类型的元素,h1,h2…. | 元素集合 |
:animated | 获取正在执行动画效果的元素 | 元素集合 |
注:选择器animated在捕捉动画效果元素时,先自定义一个动画效果函数animateIt(),然后执行该函数,选择器才能获取动画效果元素,并addClass
3-2 内容过滤选择器
选择器 | 功能 | 返回值 |
---|
:contains(text) | 包含给定文本的元素 | 元素集合 |
:empty | 所有不包含子元素或文本的元素 | 元素集合 |
:has(selector) | 含有选择器所匹配的元素 | 元素集合 |
:parent | 含有子元素或文本的元素 | 元素集合 |
3-3 可见性过滤选择器
选择器 | 功能 | 返回值 |
---|
:hidden | 所有不可见元素,或type为hidden的元素 | 元素集合 |
:visible | 所有可见元素 | 元素集合 |
注: :hidden选择器所选择的包括样式为display:none所有元素、属性type=“hidden”和样式为visibility:hidden的所有元素。
3-4 属性过滤选择器
选择器 | 功能 | 返回值 |
---|
[attribute] | 包含给定属性的元素 | 元素集合 |
[attribute =value] | 等于给定属性是某个特定值 | 元素集合 |
[attribute !=value] | 不等于 | 元素集合 |
[attribute ^=value] | 以某些值开始 | 元素集合 |
[attribute$ =value] | 以某些值结尾 | 元素集合 |
[attribute *=value] | 包含某些值 | 元素集合 |
[selector1][selector1] | 满足多个条件的符合属性的元素 | 元素集合 |
3-5 子元素过滤选择器
选择器 | 功能 | 返回值 |
---|
:nth-child(eq|even|odd|index) | 获取每个父元素下的特地位置元素,索引号从1开始c元素集合 | |
:first-child | 每个父元素下的第一个子元素 | 元素集合 |
:last-child | 最后一个子元素 | 元素集合 |
:only-child | 获取每个父元素下的仅有一个子元素 | 元素集合 |
3-6 表单对象属性过滤选择器
选择器 | 功能 | 返回值 |
---|
:enable | 获取表单中所有属性为可用的元素 | 元素集合 |
:disable | 不可用 | 元素集合 |
:checked | 表单中所有被选中的元素 | 元素集合 |
:selected | 表单中所有被选中option的元素 | 元素集合 |
表单选择器
4-1 表单选择器
选择器 | 功能 | 返回值 |
---|
:input | 获取所有input、textarea、select | 元素集合 |
:text | 所有单行文本框 | 元素集合 |
:password | 所有密码框 | 元素集合 |
:radio | 单选按钮 | 元素集合 |
:checkbox | 复选框 | 元素集合 |
:submit | 提交按钮 | 元素集合 |
:image | 图像域 | 元素集合 |
:reset | 重置按钮 | 元素集合 |
:bottom | 所有按钮 | 元素集合 |
:file | 文件域 | 元素集合 |
因为每次都打开Wiz找,就干脆都放到博客里来了。
参考文献:
〔1〕陶国荣 . jQuery权威指南[M] . 机械工业出版社 . 2011