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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

嘗試定位無(wú)序列表中的特定數(shù)字 LI 項(xiàng)目并附加 html

嘗試定位無(wú)序列表中的特定數(shù)字 LI 項(xiàng)目并附加 html

FFIVE 2024-01-03 14:27:08
問(wèn)候堆棧溢出,我已將 html 代碼保存為名為“test”的 js 變量。然后,我嘗試定位特定的(第 5 個(gè))li 項(xiàng)目,并將 HTML 附加到該項(xiàng)目下方的一行中:var target = $("ul[class='productWrapper']>li:nth-child(5)"); $(test).insertAfter($(target));我相信我在嘗試定位 LI 元素時(shí)遇到語(yǔ)法問(wèn)題,并且不確定 insertAfter 是否是用于此任務(wù)的正確方法。歡迎您提出所有想法!
查看完整描述

1 回答

?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊

我冒昧地在它周?chē)砑恿烁啾尘靶畔ⅲ坪豕ぷ鞯煤芎?。我稍微改變了你的語(yǔ)法,但沒(méi)有改變所討論的主線(xiàn)。有兩個(gè)元素只是為了清楚地表明 .insertAfter() 擊中了正確的元素,而且只有那個(gè)元素。


這是底部帶有腳本的 HTMl。


<html dir="ltr">

<head>

? ? <meta charset="UTF-8" />

? ? <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>

? ? <style>

? ? ? ? body { display: flex; flex-direction: column; }

? ? ? ? ul { display: inline-block; list-style-type: none; text-align: left; background: #ccc; border-radius: 1rem; padding: 1rem; margin: 2rem auto; }

? ? ? ? .inserted { color: green;}

? ? </style>

</head>

<body>

? ? <ul class="productWrapper">

? ? ? ? <li>First</li>

? ? ? ? <li>Second</li>

? ? ? ? <li>Third</li>

? ? ? ? <li>Fourth</li>

? ? ? ? <li>Fifth</li>

? ? ? ? <li>Sixth</li>

? ? </ul>

? ? <ul class="someOtherClass">

? ? ? ? <li>Other First</li>

? ? ? ? <li>Other Second</li>

? ? ? ? <li>Other Third</li>

? ? ? ? <li>Other Fourth</li>

? ? ? ? <li>Other Fifth</li>

? ? ? ? <li>Other Sixth</li>

? ? </ul>


? ? <script src="http://code.jquery.com/jquery-3.4.1.min.js"></script>

? ? <script>

? ? ? ? const $target = $(`ul[class='productWrapper']>li:nth-child(5)`)

? ? ? ? const $test = $(`<li class='inserted'>Inserted after fifth</li>`);

? ? ? ? $test.insertAfter($target);

? ? </script>

</body>

</html>

頁(yè)面完全加載并且腳本完成后,這就是頁(yè)面的外觀,我相信這就是您的想法。

https://img1.sycdn.imooc.com/6594fe610001f28c01520355.jpg

查看完整回答
反對(duì) 回復(fù) 2024-01-03
  • 1 回答
  • 0 關(guān)注
  • 138 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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