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

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

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

本文實(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>第二個(gè)元素</a>
      <a>:last-child</a>
    </div>
    <div class="div">
      <a>:first-child</a>
    </div>
    <div class="div">
      <a>:first-child</a>
      <a>第二個(gè)元素</a>
      <a>:last-child</a>
    </div>
  </div>

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

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

  <script type="text/javascript">
    //查找class="first-div"下的只有一個(gè)子元素的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>第二個(gè)元素</a>
      <a>第三個(gè)元素</a>
      <a>:last-child</a>
    </div>
    <div class="div">
      <a>:first-child</a>
      <a>第二個(gè)元素</a>
    </div>
    <div class="div">
      <a>:first-child</a>
      <a>第二個(gè)元素</a>
      <a>第三個(gè)元素</a>
      <a>:last-child</a>
    </div>
  </div>

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

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

</body>

</html>

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

相關(guān)文章

最新評論

吴堡县| 连城县| 大厂| 喀喇沁旗| 莱西市| 清河县| 友谊县| 金昌市| 辽中县| 北票市| 石门县| 垫江县| 平武县| 江门市| 登封市| 仪征市| 奉贤区| 和顺县| 措美县| 徐闻县| 萍乡市| 高碑店市| 岫岩| 保德县| 房山区| 阿坝县| 济宁市| 财经| 衡山县| 石家庄市| 子洲县| 如东县| 麻江县| 双牌县| 南和县| 阳西县| 依安县| 崇义县| 盐津县| 响水县| 贵港市|