How does jquery get the current Li element, which is the first number?
User asked:
For example, there is a list of Li, if you know the current Li is the first few Li elements:
<ul>
<li></li>
<li></li>
<li></li>
</ul>
Structure like this, how do I know the current operation of Li is the first few
Solution Case:
<! DOCTYPE html>
<meta charset= "Utf-8" >&NBSP;
< Meta name= "Author" content= "http://www.45it.com/"/>
<title> ant tribe </title>
< Style type= "Text/css" >
ul{
list-style:none;
width:100px;
height:25px;
line-height:25px;
font-size:12px;
}
</STYLE>&NBSP;&NBSP
<script type= "Text/javascript" >&NBSP;&NBSP;&NBSP;
Window.onload=function () {
var Obox=document.getelementbyid ("box");
var Oshow=document.getelementbyid (" Show ");
var lis=obox.getelementsbytagname (" Li ");
for (Var index=0;index< lis.length;index++) {
lis[index].theindex=index;
lis[ Index].onclick=function () {
oshow.innerhtml=this. theindex;
}
}
}
</script>
</HEAD>&NBSP
<body>
<div> Order of the current element: <span id= "Show" ></span></div> &NBSP
<ul id= "box" >&NBSP;
<li> ant tribe </li>
<li> Ant tribe two </li >
<li> ant tribe three </li>
<li> Ant tribe four </li>
<li > Ant Tribe five </li>
<li> ant tribe six </li>
</ul>
</body> &NBSP