— 基本選擇器
— $("#txt").css("background-color","red");
— 設(shè)置id為txt的元素
— $("p").css("background-color","blue");
— 設(shè)置p元素
— $(".myclass").css("background-color","yellow");
— 設(shè)置class為myclass的元素
— $(".myclass,#txt").css("background-color","gray");
— 設(shè)置class為myclass以及id為txt的元素
— 層次選擇器
— $("#mydiv span").css("background-color","green");
— 設(shè)置mydiv所有span子孫元素
— $("#mydiv>span").css("background-color","pink");
— 設(shè)置mydiv所有span兒子元素
— $("#mydiv+span").css("background-color","pink");
— 設(shè)置mydiv后所有span兄弟元素
— 表單選擇器
— $(":input").css("background-color","green");
— 設(shè)置所有表單元素
— $(":text").css("background-color","pink");
— 設(shè)置所有文本框
— $(":button").css("background-color","pink");
— 設(shè)置所有按鈕
— 基本過濾器
— $(".class1:first").css("background-color","green");
— 設(shè)置所有class是class1的元素的第一項(xiàng)
— $(".class1:last").css("background-color","green");
— 設(shè)置所有class是class1的元素的最后一項(xiàng)
— $(".class1:even").css("background-color","green");
— 設(shè)置所有class是class1的元素的偶數(shù)項(xiàng)
— $(".class1:odd").css("background-color","green");
— 設(shè)置所有class是class1的元素的奇數(shù)項(xiàng)
— $(".class1:eq(3)").css("background-color","green");
— 設(shè)置所有class是class1的元素中下標(biāo)為3的項(xiàng)
— $(".class1:gt(3)").css("background-color","green");
— 設(shè)置所有class是class1的元素中下標(biāo)大于3的項(xiàng)
— $(".class1:lt(3)").css("background-color","green");
— 設(shè)置所有class是class1的元素中下標(biāo)小于3的項(xiàng)
— $(".class1:not(p)").css("background-color","green");
— 設(shè)置所有class是class1的元素中不為p的項(xiàng)
— 屬性過濾器
— $(".class1[id]").css("background-color","green");
— 設(shè)置所有class是class1的元素中具有id屬性的項(xiàng)
— $(".class1[name='txt']").css("background-color","green");
— 設(shè)置所有class是class1的元素中name屬性值為txt的項(xiàng)
— $(".class1[name!='txt']").css("background-color","green");
— 設(shè)置所有class是class1的元素中name屬性值為txt的項(xiàng)
— $(".class1[name^='txt']").css("background-color","green");
— 設(shè)置所有class是class1的元素中name屬性值以txt開頭的項(xiàng)
— $(".class1[name$='txt']").css("background-color","green");
— 設(shè)置所有class是class1的元素中name屬性值以txt結(jié)尾的項(xiàng)
— $(".class1[name*='txt']").css("background-color","green");
— 設(shè)置所有class是class1的元素中name屬性值包含txt的項(xiàng)
— $(".class1[id][name='txt']").css("background-color","green");
— 設(shè)置所有class是class1的元素中有id屬性并且name屬性值為txt的項(xiàng)
— 表單過濾器
— $(":text:disabled").css("background-color","green");
— 設(shè)置所有禁用的文本框
— $(":button:enabled").css("background-color","green");
— 設(shè)置所有啟用的按鈕
— $(":checkbox:checked").css("background-color","green");
— 設(shè)置所有選中的復(fù)選框
— 內(nèi)容過濾器
— $("div:contains('gcd') ").css("background-color","green");
— 設(shè)置所有包含gcd字符串的div
— $("div:has(p)").css("background-color","green");
— 設(shè)置所有包含段落的div
— $("td:empty").css("background-color","green");
— 設(shè)置所沒有內(nèi)容的單元格