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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

有根據(jù)內(nèi)容獲取節(jié)點的方法么

有根據(jù)內(nèi)容獲取節(jié)點的方法么

正在回答

6 回答

<body>


??<ul?id="test">

????<li>JavaScript</li>

????<li>HTML</li>

??</ul>


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

????//?var?otest?=?document.getElementById("test");

????//?//創(chuàng)建一個新的結(jié)點,為節(jié)點修改內(nèi)容,或者其它屬性,將該節(jié)點通過appendchild()添加給其它節(jié)點

????//?var?newnode?=?document.createElement("li");

????//?newnode.innerHTML?=?"PHP";

????//?otest.appendChild(newnode);


????//插入結(jié)點insertBefore(newnode,?node)向已有的子節(jié)點前插入一個新的子節(jié)點

????var?otest_2?=?document.getElementById("test");

????var?nodeList?=?otest_2.childNodes;

????console.log(nodeList);


????function?insertNode(innerhtml,?string)?{

??????var?newnode?=?document.createElement("li");

??????var?newtext?=?document.createTextNode(string);

??????newnode.appendChild(newtext);

??????for?(let?i?=?0;?i?<?nodeList.length;?i++)?{

????????if?(nodeList[i].innerHTML?==?innerhtml)?{

??????????//

??????????otest_2.insertBefore(newnode,?nodeList[i]);

????????}

??????}

????}


????insertNode("HTML","PHP");

????//?insertNode("PHP","你可以的");

??</script>


</body>


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

你是卿嘉俊?

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

應(yīng)該是讓練習(xí)這個:

<script?type="text/javascript">??var?otest?=?document.getElementById("test");????var?li?=?document.createElement('li');??li.innerHTML="PHP";??var?html?=?otest.childNodes[otest.childNodes.length-1];??otest.insertBefore(li,?html);</script>


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

根據(jù)內(nèi)容找到子節(jié)點:

<!DOCTYPE HTML>

<html>

<head>

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

<title>無標(biāo)題文檔</title>

</head>

<body>


<ul id="test"><li>JavaScript</li><li>HTML</li></ul>?

?

<script type="text/javascript">


? var otest = document.getElementById("test");??

? var newnode = document.createElement("li");

? newnode.innerHTML="php";

? var num = otest.childNodes.length;

? for(var i=0;i<num;i++){

? ? ? if(otest.childNodes[i].innerHTML=="HTML"){

? ? ? ? ?otest.insertBefore(newnode,otest.childNodes[i]);?

? ? ? }

? }

??

? document.write(otest.childNodes.length);

??

??

</script>?


</body>

</html>


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

好像是用:node.innerHTML,

這樣?otest.childNodes[i].innerHTML == "HTML"

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

沒有.

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

舉報

0/150
提交
取消

有根據(jù)內(nèi)容獲取節(jié)點的方法么

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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