課程
/前端開發
/jQuery
/jQuery基礎 (一)—樣式篇
我想問問他明明使用的是a:first為什么在第二個div里面增加文本內容???
2018-09-27
源自:jQuery基礎 (一)—樣式篇 3-2
正在回答
個人理解...............................
<h3>.html()與.text()</h3>
? ? <div class="left first-div">
? ? ? ? <div class="div">
? ? ? ? ? ? 整個div的子節點都被替換了
? ? ? ? </div>??
? ? ? ? ? ? <a>:first-child</a>
? ? ? ? ? ? <a>第二個元素</a>
? ? ? ? ? ? <a>:last-child</a>
? ? ? ? </div>
? ? </div>
此時.left a:first匹配到的是第二個div的第一個<a>標簽
html()將第一個div中的<a>標簽覆蓋掉了,所以 .left a:first 匹配到的是第二個div的第一個 <a>標簽
舉報
jQuery初入開啟樣式修煉,體驗萬能的jQuery樣式集搭建網站布局
1 回答$(".first-div a:first-child").css("color", "#CD00CD");?
1 回答為什么寫$(".first-div a:first-child")查找才有反應,而寫$("a:first-child.first-div ")不行??
4 回答$(".first-div a:first-child").css("color", "#CD00CD");
1 回答為什么最后一題a:first返回了a的3個內容?求詳細解答,多謝
3 回答為什么最后一步同樣是 $(".left a:first").text卻控制的是第二個div里的元素了
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-02-18
個人理解...............................
<h3>.html()與.text()</h3>
? ? <div class="left first-div">
? ? ? ? <div class="div">
? ? ? ? ? ? 整個div的子節點都被替換了
? ? ? ? </div>??
? ? ? ? <div class="div">
? ? ? ? ? ? <a>:first-child</a>
? ? ? ? ? ? <a>第二個元素</a>
? ? ? ? ? ? <a>:last-child</a>
? ? ? ? </div>
? ? </div>
此時.left a:first匹配到的是第二個div的第一個<a>標簽
2018-09-28
html()將第一個div中的<a>標簽覆蓋掉了,所以 .left a:first 匹配到的是第二個div的第一個 <a>標簽