Este artigo descreve o método de adicionar conteúdo do nó a um formulário dinamicamente. Compartilhe para sua referência. Os detalhes são os seguintes:
1. Código
Copie o código da seguinte forma: <! Doctype html public "-// w3c // dtd xhtml 1.0 transitória // pt" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<Title> Adicionar nó </title>
<script type = "text/javascript">
função newPicture () {
var picElement = document.createElement ("img");
picElement.src = "Images/success.jpg";
picElement.width = 100;
picElement.Height = 100;
document.body.appendChild (picElement);
}
função newNode () {
var olelement = document.getElementById ('Answers');
var lielement = document.createElement ('li');
var inputElement = document.createElement ('input');
inputElement.type = "text";
inputElement.name = "Resposta";
lielement.appendChild (inputElement);
Olelement.AppendChild (Lielement);
}
</script>
</head>
<Body>
<div>
<input type = "button" name = "button" value = "Adicione uma imagem" onclick = "javascript: newPicture ();"/>
<input type = "button" name = "button" value = "Adicione uma opção" onclick = "javascript: newNode ();" /> <r />
<ol id = "Answers">
<li> <input type = "text" name = "Resposta" /> </li>
</ol>
</div>
</body>
</html>
2. Renderizações do programa:
Espero que este artigo seja útil para a programação JavaScript de todos.