Today in a lesson online review js, suddenly stuck in a small example. Repeated several times is an error. Finally, we found the source of the error.
Here is a record, beware of later forget again.
Error code:
<Body> <PID= "Intro">Course List</P> <ul> <Lititle= "1th li">Html</Li> <Li>Css</Li> <Lititle= "3rd li">Javascript</Li> <Lititle= "4th li">Jquery</Li> <Li>Html5</Li> </ul> <P>The following is a non-empty Li tag that gets the title value:</P><Scripttype= "Text/javascript"> varCon=document.getElementsByTagName ("Li"); for (varI=0; I<Con.length;i++){ vartext=Con.getattribute ("title"); if(Text!=NULL) {document.write (text+"<br>"); } } </Script> </Body>
Correct code:
<Body> <PID= "Intro">Course List</P> <ul> <Lititle= "1th li">Html</Li> <Li>Css</Li> <Lititle= "3rd li">Javascript</Li> <Lititle= "4th li">Jquery</Li> <Li>Html5</Li> </ul> <P>The following is a non-empty Li tag that gets the title value:</P><Scripttype= "Text/javascript"> varCon=document.getElementsByTagName ("Li"); for (varI=0; I<Con.length;i++){ vartext=Con[i].getattribute ("title"); if(Text!=NULL) {document.write (text+"<br>"); } } </Script>
Note When you use the GetAttribute () method, the obtained label element must be labeled subscript. GetAttribute () considers an element as an array. If you do not write the subscript getattribute () error.
GetAttribute () How to use small notes