jQuery-基础知识

2021/1/8 jQuery
// 初始化
$(document).ready(function() {})
----------------------------------------------------------------------------------------------
// 选择器
1. $('#id') // id 选择器
2. $('div') // ele 选择器,返回数组
3. $('.class') // class 选择器,共同的类返回数组,单独返回一个
4. $('*') // 通配符选择器,返回全部元素
5. $('#id, .class, div') // 多项选择器,合并返回数组
6. $('ancestor descendant') // 层级选择器(祖孙) ,可数组,可单独
7. $('parent > child') // 层级选择器(父子),子元素的第一代
8. $('prev + next') // 层级选择器(下一个),后面紧跟的元素
9. $('prve ~ siblings') // 层级选择器(兄弟),后面所有 siblings 元素
10. $('[class]') // 属性选择器,选择有 class 值的所有元素
11. $('[class = A]') // 属性选择器,选择 class 值为 A 的元素
12. $('[class != A]') // 属性值选择器,选择 class 值不为 A 的所有元素
13. $('[class ^= A]') // 属性值选择器,选择 class 值开头为 A 的所有元素
14. $('[class $= A]') // 属性值选择器,选择 class 值结尾为 A 的所有元素
15. $('[class *= A]') // 属性值选择器,选择 class 值包含为 A 的所有元素
16. $('[class][class = A]') // 多个属性值选择器,选择有 class 值并且 class 值为 A 的所有元素
----------------------------------------------------------------------------------------------
// 过滤器
1. :first-child // 第一个孩子
2. :last-child // 最后一个孩子
3. :nth-child(n|even|odd|formula) // 第几个孩子
4. :nth-last-child(n|even|odd|formula) // 倒数第几个孩子
5. :only-child // 独生子
6. :first-of-type // 第一个类型
7. :last-of-type // 最后一个类型
8. :nth-of-type(n|even|odd|formula) // 第几个类型
9. :nth-last-of-type(n|even|odd|formula) // 倒数第几个类型
10. :only-of-type // 独生子
11. 参数解释
  1. n 为数字,表示第几个
  2. even 表示偶数
  3. odd 表示积数
  4. formula 表示表达式,如 2n3n+1
12. 表单相关
  1. :input // 可以选择 <input>、<textarea>、<select>、<button>
  2. :text // 匹配所有的单行文本框和 input[type = 'text'] 一样
13. 其他的 input 的 type
  1. :password
  2. :radio
  3. :checkbox
  4. :image
  5. :reset
  6. :button
  7. :file
  8. :enabled // 匹配所有可用元素
  9. :disabled // 匹配所有不可用元素
  10. :checked // 匹配所有选中的被选中元素(复选框、单选框)
  11. :selected // 匹配所有选中的 option 元素
----------------------------------------------------------------------------------------------
// 查找和过滤
1. ele.find(expr|object|ele) // 搜索所有与指定表达式匹配的元素
2. ele.children([expr]) // 取得一个包含匹配的元素集合
3. ele.parent([expr]) // 取得一个包含着所有匹配元素的唯一父元素的元素集合
4. ele.next([expr]) // 紧跟的下一个
5. ele.prev([expr]) // 紧跟的上一个
6. ele.eq(index|-index) // 获取当前链式操作中第 n 个 jquery 对象,负数就往后数
7. ele.siblings([expr]) // 获取同级全部元素
8. ele.filter(expr|object|ele|fn) // 筛选出与指定表达式匹配的元素集合
9. 参数解释
  1. expr 表示字符串值,包含提供匹配当前元素集合的选择器表达式
  2. object 表示现有的 jquery 对象,以匹配当前的对象
  3. ele 表示一个用于匹配元素的 DOM 元素
  4. fn 表示一个函数,用来作为测试元素的集合
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Last Updated: 2024/6/11 14:20:38
    飘向北方
    那吾克热-NW,尤长靖