$(function(){ $('p:first').css('border','5px solid red'); $('p:last').css('border','5px dashed blue'); $('p:first+p').css('border','5px solid gray') $('#item01 li:odd').css('border','5px solid green') $('#item01 li:even').css('border','5px dashed blue') $('#item02 li:nth-child(2)').css('border','5px dashed blue') $('#item03 li:nth-child(3n+2)').css('border','5px solid blue') $('#item04 :gt(4)').css('border','5px solid red') $('#item04 :lt(3)').css('border','5px solid gray') $('#item04 :eq(2)').css('border','5px dashed blue') $('#item05 li:last-child').css('border','5px solid gray') $('#item03 li:last-child').css('border','5px solid red') }) jQuery基础过滤器:first和:last示例 这是第一个段落元素。 这是第二个段落元素。 这是第三个段落元素。 li:nth-child(odd) 筛选奇数项 Apple Pear Grape Pineapple li:nth-child(2) 筛选第二个元素 Milk Bread Coffee li:nth-child(3n+2) 筛选第3n+2个元素 Red Blue Green Yellow Orange Purple eq gt lt Milk Bread Coffee Bread Coffee Bread Coffee last-child Milk Bread Coffee Coffee 最后修改:2024 年 05 月 30 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏