Este artículo describe el método de agregar contenido de nodo a un formulario dinámicamente. Compártelo para su referencia. Los detalles son los siguientes:
1. Código
Copie el código de la siguiente manera: <! 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">
<Evista>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<title> Agregar nodo </title>
<script type = "text/javaScript">
función newPicture () {
var picelement = document.createElement ("img");
Picelement.src = "Images/Succes.jpg";
Picelement.Width = 100;
Picelement.Height = 100;
document.body.appendChild (Picelement);
}
función newnode () {
var olelement = document.getElementById ('respuestas');
var lineLement = document.createElement ('li');
var inputelement = document.createElement ('input');
inputelement.type = "text";
inputelement.name = "Respuesta";
lelement.appendChild (InputElement);
olelement.appendChild (Lielement);
}
</script>
</ablo>
<Body>
<div>
<input type = "button" name = "button" value = "Agregar una imagen" onClick = "javaScript: newpicture ();"/>
<input type = "button" name = "button" value = "Agregar una opción" onClick = "javaScript: newNode ();" /> <Br />
<ol id = "respuestas">
<li> <input type = "text" name = "respuesta" /> </li>
</ol>
</div>
</body>
</html>
2. Renderizaciones del programa:
Espero que este artículo sea útil para la programación de JavaScript de todos.