第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

class問題

<!DOCTYPE html>

<html>


<head>

? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

? ? <title></title>

? ? <link rel="stylesheet" href="imooc.css" type="text/css">

? ? <script src="https://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元素

? ? ? ? //針對(duì)所有父級(jí)下的第一個(gè)

? ? ? ? $('.first-div a:first-child').css("color", "#CD00CD");

? ? </script>


? ? <script type="text/javascript">

? ? ? ? //查找class="first-div"下的最后一個(gè)a元素

? ? ? ? //針對(duì)所有父級(jí)下的最后一個(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>




上面代碼中加粗的? ?class不是等于"left first-div"嘛? ?和下面加粗的代碼不應(yīng)該寫成$(".left first-div ....")嗎?

正在回答

1 回答

left和first-div 是兩個(gè)樣式? ?他后面的只是要查找class="first-div"下的第一個(gè)a元素

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

Flay_Away 提問者

謝謝你,我知道了!不管是class或者是id它們等于后面加空格的話,都相當(dāng)于同一個(gè)元素給了兩種樣式,是吧。
2018-09-10 回復(fù) 有任何疑惑可以回復(fù)我~
#2

Flay_Away 提問者

看到后面有講的,哈哈。
2018-09-10 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)