js removechild()usage <body> <p id = "p1"> <b> javascript </b> world!</p> <script言語= "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 = "親ノード/n"+nodestatus(親)+"/n"; //要素ノードpの最後の子を返しますlast = parent.lastchild; msg+= "削除前:lastChild-"+nodestatus(last)+"/n"; //ノードPの最後の子を削除し、b parent.removechild(last)になります。 last = parent.lastchild; msg+= "削除後:lastChild-"+nodestatus(last)+"/n";アラート(MSG); - > </script> </body> <html> <head> <title> jsコントロールノードの追加と削除</title> </head> <script type = "text/javascript"> var all; function addparagraph(){all = document.getElementById( "段落")。チャイルドノード; var newelement = document.createelement( "p"); var seq = all.length + 1; //新しい属性を作成するvar newattr = document.createattribute( "id"); newattr.nodevalue = "p" + seq; newElement.setattribute(newattr); //テキストコンテンツの作成var txtnode = document.createTextNode( "段落" + seq); // node newElement.AppendChild(txtnode); document.getElementById( "段落")。 } function delparagraph(){all = document.getElementById( "段落")。チャイルドノード; document.getElementById( "段落")。RemoveChild(all [all.length -1]); } </script> <style> p {background-color:#e6e6e6; } </style> <body> <center> <入力タイプ= "button" value = "node" onclick = "addparagraph();"/> <input type = "button" value = "delete node" onclick = "delaparagraph();"/> <div id = "paragraphs"> <p id = "p1"> paragraph1 </p> p </div> </center> </body> </html>上記の記事「JS Operation Dom」 - ノードを追加および削除する簡単な例は、私があなたと共有するすべてのコンテンツです。参照を提供できることを願っています。wulin.comをもっとサポートできることを願っています。