Vous pouvez modifier dynamiquement des éléments en HTML via JavaScript
Ajouter des éléments à HTML
Tout d'abord, vous devez créer une balise, puis ajouter le contenu correspondant à la balise, puis ajouter la balise créée à l'emplacement correspondant.
<! Doctype html public "- // w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns = "http://www.w3.org/1999/xhtml"> <éad- head> <meta http-equiv = "contenu-type" contenu = "text / html; charset = gb2312" /> <t titre> Test Document </Title> <script type = "text / javascript"> function Document.CreateElement ("P"); var node = document.CreateTextNode ("Ajouter un nouveau paragraphe"); element.ApendChild (nœud); x = document.getElementById ("Demo"); x.ApendChild (élément); } </ script> </ head> <body> <div id = "Demo"> <p> Il s'agit du premier paragraphe </p> </ div> <input type = "Button" value = "bouton" onClick = "add ()" /> </ body> </html>Supprimer un élément en HTML
<! Doctype html public "- // w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns = "http://www.w3.org/1999/xhtml"> <éread> <méta http-equiv = "contenu-type" contenu = "text / html; charset = gb2312" /> <itle> test document </ title> <script type = "text / javascrip document.getElementById ("Demo"); var child = document.getElementById ("p1"); père.removechild (enfant); } </ script> </ head> <body> <div id = "Demo"> <p id = "p1"> Il s'agit du premier paragraphe </p> <p id = "p2"> Il s'agit du deuxième paragraphe </p> </ div> <entrée = "Button" value = "Delete" onClick = "Deletee ()" /> </ody> </html>