JS creates an element node and adds the node as a child of the specified node in the document

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.