JS renoveChild () useage <body> <p id = "p1"> Willkommen zu <b> JavaScript </b> Welt! if (node.nodeName! = null) {temp+= "nodeName ="+node } 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"; Temperatur zurückgeben; } var parent = document.getElementById ("p1"); var msg = "Elternknoten/n"+nodestatus (übergeordnet)+"/n"; // das letzte Kind des Elementknotens P last = parent.lastchild zurückgeben; msg+= "Vor dem Löschen: lastChild-"+nodestatus (last)+"/n"; // Löschen Sie das letzte Kind des Knotens P und wird B -Parent.removechild (letztes); last = parent.lastchild; msg+= "Nach dem Löschen: lastChild-"+nodestatus (last)+"/n"; Alarm (MSG); -> </script> </body> <html> <kopf> <titels> js steuert und löschen Knoten </title> </head> <skript type = "text/javaScript"> var alle; Funktion addPragraph () {all = document.getElementById ("Absätze"). Childnodes; var newElement = document.createelement ("p"); var seq = all.length + 1; // Erstellen Sie ein neues Attribut var newAttr = document.Createattribute ("id"); newAttr.nodeValue = "P" + SEQ; newElement.setattribute (newAttr); // Textinhalt erstellen var txtnode = document.createTextNode ("Absätze" + SEQ); // Node NewElement.AppendChild (txtNode) hinzufügen; document.getElementById ("Absätze"). appendChild (NewLeement); } function delparagraph () {alle = document.getElementById ("Absätze"). Childnodes; document.getElementById ("Absätze"). removeChild (alle [all.length -1]); } </script> <style> p {Hintergrundfarbe: #e6e6e6; } </style> <body> <center> <Eingabe type = "button" value = "node add" onclick = "addParAgraph ();"/> <Eingabe type = "button" value = "node" onclick = "delparagraph (); </div> </center> </body> </html>Der obige Artikel "JS Operation DOM" - Ein einfaches Beispiel für das Hinzufügen und Löschen von Knoten ist der gesamte Inhalt, den ich mit Ihnen teile. Ich hoffe, Sie können Ihnen eine Referenz geben und ich hoffe, Sie können wulin.com mehr unterstützen.