js removeChild () usage <body> <p id = "p1"> <b> javaScript </b> world에 오신 것을 환영합니다! </p> <script language = "javaScript"type = "text/javaScript"> <!- 함수 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"; 반환 온도; } var parent = document.getElementById ( "p1"); var msg = "부모 노드/n"+nodestatus (부모)+"/n"; // 요소 노드의 마지막 아이를 반환 p last = parent.lastChild; msg+= "삭제 전 : LastChild-"+Nodestatus (last)+"/n"; // 노드 P의 마지막 자식을 삭제하고 b 부모가됩니다 .removeChild (마지막); last = parent.lastchild; msg+= "삭제 후 : LastChild-"+nodestatus (last)+"/n"; 경고 (MSG); -> </script> </body> <html> <head> <title> js 컨트롤 노드 추가 및 삭제 </title> </head> <Script Type = "Text/JavaScript"> var all; 함수 addParagraph () {all = document.getElementById ( "단락"). childnodes; var newlement = document.createElement ( "P"); var seq = all.length + 1; // 새 속성 생성 var newattr = document.createAttribute ( "id"); newattr.nodevalue = "p" + seq; Newlement.setattribute (Newattr); // 텍스트 콘텐츠 작성 var txtNode = document.createTxtNode ( "단락" + seq); // Node NewElement.appendChild (TxtNode)를 추가합니다. document.getElementById ( "단락"). AppendChild (Newlement); } function deLPARAGRAPH () {all = document.getElementById ( "단락"). childnodes; document.getElementById ( "단락"). removeChild (All [All.Length -1]); } </script> <tyle> p {배경색 : #e6e6e6; } </style> <body> <center> <input type = "button"value = "add add node"onclick = "addparagraph ();"/> <input type = "value ="delete node "onclick ="deelparagraph (); "/> <div id ="paragraphs "> <p id ="p1 "> <p> <p> <p. </div> </center> </body> </html>위의 기사 "JS Operation Dom" - 노드를 추가하고 삭제하는 간단한 예는 내가 공유하는 모든 컨텐츠입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.