1 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD">2 <HTML>3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">5 <title>Untitled Document</title>6 7 <Scripttype= "Text/javascript">8 9 //creates a new element node and adds the node as a child of the specified node in the documentTen window.onload= function(){ One Alert (1); A - //1. Document.createelement (elementtagname) - //creates a new element node with a return value of a reference to the element node the //<li></li> - varLiNode=Document.createelement ("Li"); - - //2. Create a text node for "Xiamen" + //document.createTextNode (String) to create a text node - //parameter is a literal value that returns a reference to the text node. + varXmtext=document.createTextNode ("Xiamen"); A //<li> Xiamen </li> at Linode.appendchild (xmtext); - - varCitynode=document.getElementById (" City"); - //2. Elementnode.appendchild (NewChild): for Elementnode - //the newly added NewChild child node, which will act as the last elementnode of the - //a child node. in Citynode.appendchild (liNode); - } to + </Script> - the </Head> * <Body> $ <P>Which city do you like?</P>Panax Notoginseng <ulID= "City"><LiID= "BJ"name= "Beijing">Beijing</Li> - <Li>Shanghai</Li> the <Li>Tokyo</Li> + <Li>Seoul</Li> A </ul> the + <BR><BR> - <P>Which stand-alone game do you like?</P> $ <ulID= "Game"> $ <LiID= "RL">Red Police</Li> - <Li>Live</Li> - <Li>Need for Speed</Li> the <Li>Warcraft</Li> - </ul>Wuyi the <BR><BR> - Gender: Wu <inputtype= "Radio"name= "Gender"value= "Male"/>Male - <inputtype= "Radio"name= "Gender"value= "female"/>Female About $ <BR><BR> -Name<inputtype= "text"name= "username"value= "Atguigu"/> - - </Body> A </HTML>
JS creates an element node and adds the node as a child of the specified node in the document