jQuery 选择器

# jQuery 选择器 {ignore}

[toc]

## 基本选择器

1. ID 选择器: #IDname

2. class 选择器: .className

3. 标签名选择器: tagName

4. 组合选择器

5. 全局选择器: \*

6. selector,selector、selector

## 层级选择器

1. 选择器 选择器 ul li 后代元素

2. 选择器>选择器 ul>li 子元素

3. 选择器+选择器 li+li 紧邻的兄弟元素

4. 选择器~选择器 li~li 后面所有的兄弟元素

## 筛选选择器

1. :first 第一个

2. :last 最后一个

3. :eq(index) 从 0 开始

4. :lt(index) <

5. :gt(index) >

6. :odd 奇数

7. :even 偶数

8. :not(index) 排除

9. :lang()

10. :root()

11. :header 所有的标题标签

12. :focus 获取焦点的元素

13. :target 锚点指向的元素

14. :animated 正在执行动画的元素

## 内容选择器

1. :contains(text) 包含指定的文本

2. :has(selector) 包含满足条件的后代元素的元素

3. :empty 没有内容也没有子元素

4. :parent 跟 empty 相反

## 可见性选择器

1. :hidden 不可见的元素

2. :visible 可见的元素

## 属性选择器

1. [attribute] 取拥有 attribute 属性的元素

2. [attribute = value]

3. [attribute != value]

4. [attribute ^= value] 以... 开头

5. [attribute $= value] 以... 结尾

6. [attribute *= value] 以... 包含

## 子元素选择器

1. :first-child 取第一个元素

2. :last-child 取最后一个元素

3. :nth-child(index)

1. :nth-child(x) 从 x 开始

2. :nth-child(odd)、:nth-child(even) 对应的元素是从奇数开始、对应的元素是从偶数开始

3. :nth-child(xn+y) 表达式

4. :nth-last-child(index)

5. :only-child 当某个元素是父元素唯一的子元素时

6. :first-of-type

7. :last-of-type

8. :nth-of-type(index) 从 1 开始

9. :nth-last-of-type(index)

10. :only-of-type

## 表单对象属性过滤选择器

1. enabled 取可用的元素

2. disabled 取不可用的元素

3. checked 默认选中

4. selected 下拉列表中被选中的元素

## 表单选择器

1. input (取 input,textarea,select,button 元素)

2. text (取单行文本框元素)

3. password (取密码框元素)

4. radio (取单选框元素)

5. checkbox (取复选框元素)

6. submit (取提交按钮元素)

## 表单对象选择器

## 混淆选择器

## 方法中的值

1. slow-慢

2. fast-快

3. 毫秒

## 隐藏/显示

1. hide-隐藏

2. show-显示

3. toggle-来回切换

## 淡入淡出

1. fadeIn-淡入

2. fadeOut-淡出

3. fadeToggle-来回切换淡入淡出

4. fadeTo-缓缓淡出(渐变给定的不透明度)

## 滑动

1. sideDown-下滑

2. sideUp-上滑

3. sideToggle-滑动来回切换

## 动画 animate

animate({params},speed,callback)

1. params === 参数定义想成动画的 css 属性

2. speed === 参数规定效果的时长(slow、fast、毫秒)

3. callback === 参数是动画完成后所执行的函数名称

## 停止动画

jQuery stop()