JavaScript DOM Programming--03--read-write attribute node

Source: Internet
Author: User

Read-Write attribute node:

1) The value of the attribute node can be obtained and set directly through Citynode.id.

2) Get the attribute node through the GetAttributeNode method of the element node,
and read and write the property values through NodeValue.

1<HTML>2     <Head>3         <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">4         <title>Untitled Document</title>5         6         <Scripttype= "Text/javascript">7             8             //read-Write attribute node: Gets the property value and sets the property value by the element node.9 window.onload= function(){Ten                  One                 //The attribute node is a property of a specified element node. A                 //1. Get the specified element node first -                 varNameNode=document.getElementById ("name"); -                  the                 //2. Read the value of the specified property again - alert (namenode.value); -                  -                 //3. Set the value of the specified property. + Namenode.value= "still Silicon Valley"; -                  +                 //var nameattr = Namenode.getattributenode ("value"); A                 //alert (nameattr); at                 //alert ("--" + nameattr.nodevalue); -                 //nameattr.nodevalue = "Atguigu"; -             } -              -         </Script> -          in     </Head> -     <Body> to         <P>Which city do you like?</P> +         <ulID= "City"> -             <LiID= "BJ"name= "Beijing">Beijing</Li> the             <Li>Shanghai</Li> *             <Li>Tokyo</Li> $             <Li>Seoul</Li>Panax Notoginseng         </ul> -          the         <BR><BR> +         <P>Which stand-alone game do you like?</P> A         <ulID= "Game"> the             <binID= "RL">Red Police</Li> +             <Li>Live</Li> -             <Li>Need for Speed</Li> $             <Li>Warcraft</Li> $         </ul> -          -         <BR><BR> theName<inputtype= "text"name= "username"  - ID= "Name"value= "Atguigu"/>Wuyi     </Body> the </HTML>    

JavaScript DOM Programming--03--read-write attribute node

Related Article

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.