jQuery伪类选择器

jQuery中容易被疏忽的强大选择器和过滤器

六眼飞鱼酱① 提交于 2020-03-01 02:35:13
jQuery中选择器总体上包含了CSS3的选择器,但某些方面却由于CSS3的选择器,虽然使用各种选择器,最后也能达到目标,但在项目中,为了做的更少的代码量,使用某些特定的选择器,减少人为的判断似乎更加值得一试 1> :not(selector) 和 not(expr|ele|fn) :not(selector) not(expr|ele|fn) $("input:not(:checked)") 对于not函数的用法 $("p").not('#selected') /*使用选择器*/ $("p").not( $("#selected")[0] ) /*使用 js DOM对象而不是jQuery对象*/ $('p').not(document.getElementById('selected')) $("p").not(function(index){ //使用函数 return $(p).get(index)==$('#selected'); }) 2> :eq(index)与eq(-index|index) $("tr:eq(1)") #使用伪类选择器只能从正向0算起 $("p").eq(1) #从正向0算起 $("p").eq(-1) #从倒数第一位算起,起始值为 -1 3>:gt(index) 与lt:(index) $("tr:gt(0)") #从上向下截取 $("tr:lt