最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery選擇器之子元素選擇器詳解

 更新時間:2017年09月18日 13:50:49   作者:喵嘻嘻  
這篇文章主要為大家詳細(xì)介紹了jQuery選擇器之子元素選擇器,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了jQuery子元素選擇器,供大家參考,具體內(nèi)容如下

<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  <title></title>
  <link rel="stylesheet" href="imooc.css" rel="external nofollow" type="text/css">
  <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>

<body>
  <h2>子元素篩選選擇器</h2>
  <h3>:first-child、:last-child、:only-child</h3>
  <div class="left first-div">
    <div class="div">
      <a>:first-child</a>
      <a>第二個元素</a>
      <a>:last-child</a>
    </div>
    <div class="div">
      <a>:first-child</a>
    </div>
    <div class="div">
      <a>:first-child</a>
      <a>第二個元素</a>
      <a>:last-child</a>
    </div>
  </div>

  <script type="text/javascript">
    //查找class="first-div"下的第一個a元素
    //針對所有父級下的第一個
    $(".first-div a:first-child").css("color", "#CD00CD");
  </script>

  <script type="text/javascript">
    //查找class="first-div"下的最后一個a元素
    //針對所有父級下的最后一個
    //如果只有一個元素的話,last也是第一個元素
    $(".first-div a:last-child").css("color", "red");
  </script>

  <script type="text/javascript">
    //查找class="first-div"下的只有一個子元素的a元素
    $(".first-div a:only-child").css("color", "blue");
  </script>


  <h3>:nth-child、:nth-last-child</h3>
  <div class="left last-div">
    <div class="div">
      <a>:first-child</a>
      <a>第二個元素</a>
      <a>第三個元素</a>
      <a>:last-child</a>
    </div>
    <div class="div">
      <a>:first-child</a>
      <a>第二個元素</a>
    </div>
    <div class="div">
      <a>:first-child</a>
      <a>第二個元素</a>
      <a>第三個元素</a>
      <a>:last-child</a>
    </div>
  </div>

  <script type="text/javascript">
    //查找class="last-div"下的第二個a元素
    $(".last-div a:nth-child(2)").css("color", "#CD00CD");
  </script>

  <script type="text/javascript">
    //查找class="last-div"下的倒數(shù)第二個a元素
    $(".last-div a:nth-last-child(2)").css("color", "red");
  </script>

</body>

</html>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

卢湾区| 女性| 石家庄市| 阿克| 渭南市| 盘山县| 宣汉县| 大关县| 兴义市| 德州市| 新宾| 甘孜| 武清区| 鄂温| 秀山| 乐至县| 淮安市| 固始县| 定远县| 双城市| 溆浦县| 新蔡县| 洪江市| 枣阳市| 习水县| 金秀| 克拉玛依市| 韶关市| 留坝县| 长丰县| 滦平县| 乌拉特后旗| 武陟县| 大新县| 渝北区| 武清区| 定边县| 富平县| 古田县| 中阳县| 桂阳县|