IT@程序员猿媛猿客栈

jquery选择器

2020-01-14  本文已影响0人  Kkite

分类

1.基本选择器

a.标签选择器(元素选择器)
b.id选择器
c.类选择器
d.并集选择器

2.层级选择器

a.后代选择器
b.子选择器

3.属性选择器

a.属性名称选择器
b.属性选择器
c.符合属性选择器
$("div[title]").css("backgroundColor","pink");                //选中含有title属性的div
$("div[title='test']").css("backgroundColor","pink");      //选中属性title值为test的div  
$("div[title!='test']").css("backgroundColor","pink");      //选中属性title值不等于test的div元素(没有属性title的也将被选中)
$("div[title^='te']").css("backgroundColor","pink");        //选中属性title值以te开头的div
$("div[title$='st']").css("backgroundColor","pink");       // 选中属性title值以st结束的div
$("div[title*='es']").css("backgroundColor","pink");      //选中属性title值含有es的div
$("div[id][title*='es']").css("backgroundColor","pink");  //选区有属性id的div元素,然后在结果中选取属性title值含有es的div元素

4.过滤选择器

a.首元素选择器
b.尾元素选择器
c.非元素选择器
d.偶数选择器
e.奇数选择器
f.等于索引选择器
g.大于索引选择器
h.小于索引选择器
i.标题选择器
$("div:first").css("backgroundColor","pink");    //选取第一个div
$("div:last").css("backgroundColor","pink");    //选取最后一个div
$("div:not(.one)").css("backgroundColor","pink");    //选取class不为one的所有div
$("div:first").css("backgroundColor","pink");    //选取第一个div
$("div:even").css("backgroundColor","pink");    //选取索引值为偶数的div
$("div:odd").css("backgroundColor","pink");    //选取索引值为奇数的div
$("div:gt(3)").css("backgroundColor","pink");    //选取索引值大于3的div
$("div:eq(e)").css("backgroundColor","pink");    //选取索引值等于3的div
$("div:lt(3)").css("backgroundColor","pink");    //选取索引值小于3的div
$("header").css("backgroundColor","pink");    //选取所有的标题元素

5.表单过滤选择器

a.可用元素选择器
b.不可用元素选择器
c.选中选择器
d.选中选择器
$("input[type='text']:enabled").val("aaa");    // 改变可用input的值为aaa
$("input[type='text']:disabled").val("aaa");     // 改变不可用input的值为aaa
$("input[type='checkbox']:checked").length;  //获取复选框选中的个数
$("#job > option:selected").length;                // 获取下拉框选中的个数

如有错误或建议欢迎大家指出与评论哈,希望这篇博文能帮助到大家,大家也可以分享给需要的人。

如需转载,请注明出处。https://www.jianshu.com/p/89ff743653f7

上一篇 下一篇

猜你喜欢

热点阅读