Copy Code code as follows:
<script type= "Text/javascript" >
Window.onload = function ()
{var topmenus = getclass (' li ', ' Topmenu ');
for (Var i=0;i < topmenus.length; i++)
{
alert (topmenus[i].innerhtml);
}
}
function GetClass (tagname,classname)//Get the element with label name TagName, class name ClassName
{
if (document.getelementsbyclassname)//support for this function
{return document.getelementsbyclassname (className);
}
Else
{var tags=document.getelementsbytagname (tagName);//Get Label
The Var tagarr=[];//is used to return the element with the class name classname
for (Var i=0;i < tags.length; i++)
{
if (Tags[i].class = = className)
{
Tagarr[tagarr.length] = tags[i];//Save the element that satisfies the condition
}
}
return Tagarr;
}
}
</script>
<body>
<ul id= "NAV" >
<li class= "Topmenu" ><a href= "#" > Product introduction </a>
<ul class= "submenu" >
<li><a href= "#" > Products 1</a></li>
<li><a href= "#" > Products 2</a></li>
<li><a href= "#" > Products 3</a></li>
<li><a href= "#" > Products 4</a></li>
<li><a href= "#" > Products 5</a></li>
<li><a href= "#" > Products 6</a></li>
</ul>
</li>
<li class= "Topmenu" ><a href= "#" > Service Introduction </a>
<ul class= "submenu" >
<li><a href= "#" > Service 1</a></li>
<li><a href= "#" > Service 2</a></li>
<li><a href= "#" > Service 3</a></li>
<li><a href= "#" > Service 4</a></li>
</ul>
</li>
<li class= "Topmenu" ><a href= "#" > Success Stories </a>
<ul class= "submenu" >
<li><a href= "#" > Case 1</a></li>
<li><a href= "#" > Case 2</a></li>
<li><a href= "#" > Case 3</a></li>
<li><a href= "#" > Case 4</a></li>
</ul>
</li>
<li class= "Topmenu" ><a href= "#" > About Us </a>
<ul class= "submenu" >
<li><a href= "#" > We 1</a></li>
<li><a href= "#" > We 2</a></li>
<li><a href= "#" > We 3</a></li>
<li><a href= "#" > We 4</a></li>
</ul>
</li>
<li class= "Topmenu" ><a href= "#" > Contact Us </a>
<ul class= "submenu" >
<li><a href= "#" > Contact 1</a></li>
<li><a href= "#" > Contact 2</a></li>
<li><a href= "#" > Contact 3</a></li>
<li><a href= "#" > Contact 4</a></li>
<li><a href= "#" > Contact 5</a></li>
<li><a href= "#" > Contact 6</a></li>
<li><a href= "#" > Contact 7</a></li>
</ul>
</li>
</ul>
</body>
Note that both Getelementsbyclassname and getElementsByTagName have s;
JS can not be used int a=1, to use the Var a=1;