jQuery伪类选择器

//伪类选择器:

  特定位置的选择器:

     jQuery(“selector:first”)//第一个

jQuery(“selector:last”)//最后一个


 

jQuery(“selector:eq(index)”)//指定位置

   <div>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

    </div>

    <script type="text/javascript">

      $(function (){

         $("img:first").css("border","solid 5px green");

         $("img:last").css("border","solid 5px red");

         $("img:eq(3)").css("border","solid 5px black");

      })

    </script>

//指定范围选择器:

jQuery(“selector:even”)//选择偶数序列

jQuery(“selector:odd”)//选择奇数序列

jQuery(“selector:gt(index)”)//大于index索引

jQuery(“selector:lt(index)”)//小于index索引

//

<div>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

    </div>

    <script type="text/javascript">

      $(function (){

         $("img:odd").css("border","solid 5px green");

         $("img:gt(2)").css("border","solid 5px black");

      })

    </script>

排除选择器:

  jQuery(“selector1:not(selector2)”)

//

<div>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

         <img src="../img/飘雪.jpg" width="200px" height="200px"/>

    </div>

    <script type="text/javascript">

      $(function (){

         $("img:gt(2)").css("border","solid 5px black");

         $("img:not(img:gt(3))").css("border","solid 5px red");

        

      })

    </script>

//特殊选择器:

jQuery(“selector:animate”)//选择动画元素

jQuery(“selector:header”)//选择标题(h1…….hn

//文本选择器:

jQuery(“selector:contains(text)”)//匹配包含text文本的序列

jQuery(“selector1:has(selector2)”)//匹配包含selector2标签的序列

jQuery(“selector:empty”)//匹配不含子元素或文本的序列

jQuery(“selector:parent”)// 匹配含子元素或文本的序

//显示状态伪类选择器:

jQuery(“selector:hidden”)//匹配所有不可见的元素jQuery(“selector:parent”)//匹配所有可见元素

 jQuery(“selector:nth-child(N)”)//匹配父元素下的第N个子元素

jQuery(“selector:first-child”)//匹配第一个子元素

jQuery(“selector:last-child”)//匹配最后一个元素

jQuery(“selector:only-child”)//匹配只有一个子元素的元素


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

有志青年(top)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值