js removeChild () use <body> <p id = "p1"> bienvenido a <b> javascript </b> world! </p> <script language = "javascript" type = "text/javascript"> <!- function nodestatus (nodo) {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"; regresar temp; } var parent = document.getElementById ("P1"); var msg = "nodo principal/n"+nodestatus (parent)+"/n"; // devuelve el último hijo del nodo de elemento P Last = Parent.lastChild; msg+= "antes de la eliminación: lastchild-"+nodestatus (last)+"/n"; // Eliminar el último hijo del nodo P y se convierte en B Parent.removechild (último); Último = parent.lastchild; msg+= "después de la eliminación: lastchild-"+nodestatus (last)+"/n"; alerta (msg); -> </script> </body> <html> <cead> <title> JS controla la adición y eliminación de nodos </title> </head> <script type = "text/javaScript"> var all; función addparagraph () {all = document.getElementById ("párrafos"). ChildNodes; var newelement = document.createElement ("P"); var seq = all.length + 1; // Cree un nuevo atributo var newattr = document.createAteTtribute ("id"); newattr.NodeValue = "P" + SEQ; Newelement.SetAttribute (NewATTR); // Crear contenido de texto var txtnode = document.createTextNode ("párrafos" + seq); // agregar nodo newelement.appendChild (txtnode); document.getElementById ("párrafos"). AppendChild (Newelement); } function delparagraph () {all = document.getElementById ("párrafos"). ChildNodes; document.getElementById ("párrafos"). RemoVeChild (all [all.length -1]); } </script> <style> P {fondo de fondo: #e6e6e6; } </ystye> <body> <center> <input type = "button" value = "add nodo" onClick = "addparagraph ();"/> <input type = "Botton" value = "Eliminar nodo" onClick = "delparagraph ();"/> <Div Id = "párrafo"> <p id = "p1"> párrafo </p> <pi = "p2" p2 "<p2" </div> </center> </body> </html>El artículo anterior "JS Operation Dom": un ejemplo simple de agregar y eliminar nodos es todo el contenido que comparto con usted. Espero que pueda darle una referencia y espero que pueda apoyar más a Wulin.com.