Get text node:
1). Step: Element node--Get child node of element node
2). If the element node has only one child node of the text node,
For example <li id= "BJ" name= "Beijing" > Beijing </li>, <p> which city do you like? </p>
You can get to the specified element node Elenode first,
Then use the EleNode.firstChild.nodeValue method to read and write the value of its text node
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 //Get text node9 window.onload= function(){Ten One //the text node must be a child node of the element node. A - //1. Get the element node where the text node resides - varBjnode=document.getElementById ("BJ"); the - //2. Defined by FirstChild to a text node - varBjtextnode=Bjnode.firstchild; - + //3. Read and write the value of the text node by manipulating the NodeValue property of the text node. - alert (bjtextnode.nodevalue); + A Bjtextnode.nodevalue= "still Silicon Valley"; at - //alert (bjtextnode); - } - - </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 <LiID= "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--04--getting text nodes