The example of this article describes the way JS dynamically adds node content to the form. Share to everyone for your reference. Specifically as follows:
1. Code
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Add Nodes </title>
<script type= "Text/javascript" >
function Newpicture () {
var picelement = document.createelement ("img");
PICELEMENT.SRC = "Images/success.jpg";
Picelement.width = 100;
Picelement.height = 100;
Document.body.appendChild (picelement);
}
function NewNode () {
var olelement = document.getElementById (' answers ');
var lielement = document.createelement (' li ');
var inputelement = document.createelement (' input ');
Inputelement.type = "text";
Inputelement.name = "Answer";
Lielement.appendchild (inputelement);
Olelement.appendchild (lielement);
}
</script>
<body>
<div>
<input type= "button" name= "button" value= "adds a picture" onclick= "javascript:newpicture (); />
<input type= "button" name= "button" value= "adds an option to" onclick= "Javascript:newnode (); /><br/>
<ol id= "Answers" >
<li><input type= "text" name= "Answer"/></li>
</ol>
</div>
</body>
2. Program Effect Chart:
I hope this article will help you with your JavaScript programming.