国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 15:24:45
字體:
供稿:網(wǎng)友

本文實例為大家分享了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)容,希望對大家的學習有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 偏关县| 宝山区| 绥芬河市| 沽源县| 仁化县| 乌鲁木齐县| 宁德市| 赣榆县| 读书| 竹溪县| 铜川市| 宁海县| 梧州市| 赤峰市| 石城县| 遵义市| 尼勒克县| 海安县| 双鸭山市| 无锡市| 朔州市| 东乡族自治县| 夏邑县| 兰考县| 惠安县| 宿州市| 永宁县| 合川市| 长沙县| 利辛县| 贡山| 湘阴县| 思茅市| 定襄县| 余姚市| 巴东县| 平顺县| 花莲市| 犍为县| 保康县| 宜丰县|