為相對(duì)的兩個(gè)方法:not()返回不滿(mǎn)足的,filter()返回滿(mǎn)足條件的
實(shí)例1:
$("p").not(":even").css("background-color","yellow");//下標(biāo)不是偶數(shù)
$("p").filter(":even").css("background-color","yellow");//下標(biāo)為偶數(shù)
實(shí)例2:
通過(guò)class辜限,id兩個(gè)條件判斷
$("p").not(".intro,#outro").css("background-color","yellow");
$("p").filter(".intro,#outro").css("background-color","yellow");
實(shí)例3:
通過(guò)函數(shù)去判斷
$("p").not(function(){
return $("span",this).length==2;}).css("background-color","yellow");
}
$("p").filter(function(){
return $("span",this).length==2;}).css("background-color","yellow");
}