JS removechild () penggunaan <body> <p id = "p1"> Selamat datang di <b> javascript </b> dunia! </p> <bahasa skrip = "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"; kembalikan suhu; } var parent = document.geteLementById ("p1"); var msg = "node induk/n"+nodestatus (parent)+"/n"; // kembalikan anak terakhir dari node elemen p last = parent.lastchild; msg+= "sebelum dihapus: lastchild-"+nodestatus (last)+"/n"; // hapus anak terakhir dari simpul P dan menjadi B Parent.removechild (terakhir); terakhir = parent.lastchild; msg+= "Setelah penghapusan: lastchild-"+nodestatus (terakhir)+"/n"; peringatan (msg); -> </script> </body> <html> <head> <title> js mengontrol menambahkan dan menghapus node </iteme> </head> <script type = "text/javascript"> var all; fungsi addParagraph () {all = document.geteLementById ("paragraf"). Childnodes; var newElement = document.createElement ("p"); var seq = all.length + 1; // Buat atribut baru var newAttr = document.createAttribute ("id"); newAttr.nodevalue = "p" + seq; newElement.setAttribute (newAttr); // Buat konten teks var txtNode = document.createTextNode ("paragraf" + seq); // tambahkan node newElement.appendChild (txtNode); document.geteLementById ("paragraf"). AppendChild (newElement); } function delparagraph () {all = document.geteLementById ("paragraf"). Childnodes; document.geteLementById ("paragraf"). Removechild (semua [all.length -1]); } </script> <tyle> p {background-color: #e6e6e6; } </style> <body> <senter> <input type = "tombol" value = "add node" onclick = "addParagraph ();"/> <input type = "Tombol" value = "hapus simpul" ontClick = "delparagraph ();"/> <v id = "paragraf"> <pd id = "p1"> paragr2 "> paragr2" paragr </parr1 "> paragr </P1"> PARAGR </P1> PARAGR </P1> PARAGR </P1> </div> </penter> </body> </html>Artikel di atas "JS Operation Dom" - contoh sederhana untuk menambahkan dan menghapus node adalah semua konten yang saya bagikan dengan Anda. Saya harap Anda dapat memberi Anda referensi dan saya harap Anda dapat mendukung wulin.com lebih lanjut.