Jquery套用了css的选择器,选择器分为:
基本选择器
1. 标签选择器$(“element”)
$(“div”)
2. ID选择器$(“#id”)
$(“#id”)
3. 类选择器$(“.class”)
$(“.class”)
4. 通用选择器
$(“*”) 选择所有元素
5. 群组选择器$(“select1,select2.select3,…,selectN”)
$(“div,span,p.styleClass”).css(“border”,”1pxsolid red”)
扩展选择器
- 层级选择器 ${“parent>child”}
其中参数parent是任意有效的选择器;child也是一个选择器,并且它是第一个选择器的子元素
${“form>input”} form 标签下的 input 标签
${“.class1>.class2”} class1 下的class2
- 后代元素选择器
${“ancestordescendant”} ancestor 可以是任意有效的选择器;descendant可以是ancestor元素的子元素、孙元素、重孙元素。
${form input} form下的input元素
- 紧邻同辈元素选择器--用于匹配所有紧邻在pre元素后面的next元素(第一个),语法格式如下
${“prev+next”}
- 相邻同辈元素选择器--用于匹配所有紧邻在pre元素后面的next元素(所有同辈元素),格式如下:
$(“prev~next”)
- 表单选择器
1) :input选择器 选择所有input、textarea、select和button元素
$(“:input”)
2) :text 选择器 选择所有单行文本框(<input type=”text” />)
$(“:text”)
3) :password选择器(<input type=”password” />)
$(“:password”)
4) :radio 选择器 选择所有 (<input type=”radio” />)
$(“:radio”)
同理有
$(“:checkbox”) $(“:checkbox:eq(0)”)
$(“:file”)
$(“:image”)
$(“:hidden”)
$(“:button”)
$(“:submit”)
$(“:reset”)