茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    js操作DOM--添加、刪除節(jié)點(diǎn)的簡(jiǎn)單實(shí)例
    來源:易賢網(wǎng) 閱讀:1371 次 日期:2016-07-25 15:24:41
    溫馨提示:易賢網(wǎng)小編為您整理了“js操作DOM--添加、刪除節(jié)點(diǎn)的簡(jiǎn)單實(shí)例”,方便廣大網(wǎng)友查閱!

    下面小編就為大家?guī)硪黄猨s操作DOM--添加、刪除節(jié)點(diǎn)的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。

    js removeChild() 用法

    <body> 

    <p id="p1">welcome to <b>javascript</b> world !</p> 

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

    <!-- 

    function nodestatus(node) 

     var temp=""; 

     if(node.nodeName!=null) 

     { 

      temp+="nodeName="+node.nodeName+"\n"; 

     } 

     else temp+="nodeName=null \n"; 

     if(node.nodeType!=null) 

     { 

      temp+="nodeType="+node.nodeType+"\n"; 

     } 

     else temp+="nodeType=null \n"; 

     if(node.nodeValue!=null) 

     { 

      temp+="nodeValue="+node.nodeValue+"\n"; 

     } 

     else temp+="nodeValue=null \n"; 

     return temp; 

    var parent=document.getElementById("p1"); 

    var msg="父節(jié)點(diǎn) \n"+nodestatus(parent)+"\n"; 

    //返回元素節(jié)點(diǎn)p的最后一個(gè)孩子 

    last=parent.lastChild; 

    msg+="刪除之前:lastChild--"+nodestatus(last)+"\n"; 

    //刪除節(jié)點(diǎn)p的最后一個(gè)孩子,變?yōu)閎 

    parent.removeChild(last); 

    last=parent.lastChild; 

    msg+="刪除之后:lastChild--"+nodestatus(last)+"\n"; 

    alert(msg); 

    --> 

    </script> 

    </body> 

    --------------------------------------------------------------

    <html>

    <head>

    <title>js控制添加、刪除節(jié)點(diǎn)</title>

    </head>

    <script type="text/javascript">

      var all;

      function addParagraph() {

        all = document.getElementById("paragraphs").childNodes;

        var newElement = document.createElement("p");

        var seq = all.length + 1;

        //創(chuàng)建新屬性

        var newAttr = document.createAttribute("id");

        newAttr.nodeValue = "p" + seq;

        newElement.setAttribute(newAttr);

        //創(chuàng)建文本內(nèi)容

        var txtNode = document.createTextNode("段落" + seq);

        //添加節(jié)點(diǎn)

        newElement.appendChild(txtNode);

        document.getElementById("paragraphs").appendChild(newElement);

      }

      function delParagraph() {

        all = document.getElementById("paragraphs").childNodes;

        document.getElementById("paragraphs").removeChild(all[all.length -1]);

      }

    </script>

    <style>

      p{

        background-color : #e6e6e6 ;

      }

    </style>

    <body>

    <center>

      <input type="button" value="添加節(jié)點(diǎn)" onclick="addParagraph();"/>

      <input type="button" value="刪除節(jié)點(diǎn)" onclick="delParagraph();"/>

      <div id="paragraphs">

        <p id="p1">段落1</p>

        <p id="p2">段落2</p>

      </div>

    </center>

    </body>

    </html>

    以上這篇js操作DOM--添加、刪除節(jié)點(diǎn)的簡(jiǎn)單實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)