1. With native JS, create an unordered list to add to Body, UL contains 5 Li, each Li contains a text type element, text element content can be customized;
<script type= "Text/javascript" >window.onload=function() { varUlnode = document.createelement ("ul"); varBodynode = document.getElementsByTagName ("Body");Bodynode[0].appendchild (Ulnode); for(vari = 0; I < 5; i++) { varLiNode = document.createelement ("li"); varTextnode = document.createTextNode ("I am a text node" +i); Linode.appendchild (Textnode); Ulnode.appendchild (LiNode); } }</script>
Operation Result:
Knowledge Points:
(1) In native JS, window.onload can call certain functions when the page is loaded (http://www.jb51.net/article/43166.htm)
function () {
(2) Create a new node:
Document.createelement ("div"); //
(3) Creating a text node
document.createTextNode (); // to create a text node
(4) Adding the last child node to a node
JS face question