美文网首页
jquery的not()和filter()方法

jquery的not()和filter()方法

作者: 丶灰太狼他叔 | 来源:发表于2018-03-01 13:53 被阅读9次

为相对的两个方法:not()返回不满足的,filter()返回满足条件的
实例1:

$("p").not(":even").css("background-color","yellow");//下标不是偶数
$("p").filter(":even").css("background-color","yellow");//下标为偶数

实例2:
通过class,id两个条件判断

$("p").not(".intro,#outro").css("background-color","yellow");
$("p").filter(".intro,#outro").css("background-color","yellow");

实例3:
通过函数去判断

$("p").not(function(){  
        return $("span",this).length==2;}).css("background-color","yellow");
}
$("p").filter(function(){  
        return $("span",this).length==2;}).css("background-color","yellow");
}

相关文章

网友评论

      本文标题:jquery的not()和filter()方法

      本文链接:https://www.haomeiwen.com/subject/nhpgxftx.html