Question: After clicking the hyperlink menu of the template in the website to a different page, add the selected style and delete the selected style from similar elements.
Solution:
HTML: for example
<Li> <span> <I class = "icon1"> </I> <a href = "/home/announcement"> notification announcement </a> </span> </LI>
<Li> <span> <I class = "icon1"> </I> <a href = "/home/classactivity"> class activities </a> </span> </LI>
<Li> <span> <I class = "icon1"> </I> <a href = "/home/halloffame"> honor list </a> </span> </ LI>
<Li> <span> <I class = "icon1"> </I> <a href = "/home/disciplinesfeedback"> subject feedback </a> </span> </LI>
<Li> <span> <I class = "icon1"> </I> <a href = "/home/memorandum"> memorandum </a> </span> </ LI>
<Li> <span> <I class = "icon1"> </I> <a href = "/teacher/announcement"> notification announcement </a> </span> </LI>
<Li> <span> <I class = "icon1"> </I> <a href = "/teacher/classactivity"> class activities </a> </span> </LI>
<Li> <span> <I class = "icon1"> </I> <a href = "/teacher/halloffame"> honor list </a> </span> </ LI>
<Li> <span> <I class = "icon1"> </I> <a href = "/teacher/disciplinesfeedback"> subject feedback </a> </span> </LI>
<Li> <span> <I class = "icon1"> </I> <a href = "/teacher/memorandum"> memorandum </a> </span> </ LI>
This is an inaccessible page. After each page is selected, add the selected style "on"
Jquery:
$ (Function (){
VaR menus = $ ("# lnav"). Children (). Find ("");
VaR hturl = Window. Location. href;
$. Each (menus, function (index, item ){
VaR url = $ (item). ATTR ("href ");
VaR Len = URL. indexof ("/"); // controller name
VaR lastlen = URL. lastindexof ("/"); // method name
If (LEN> = 0 ){
VaR T = URL. substr (Len, lastlen-1); // get the Controller name
VaR action = URL. substr (LEN); // jump link of the tag
VaR hlen = hturl. indexof (t); // whether the browser address has a controller name
If (hlen> = 0 ){
VaR haction = hturl. substr (hlen); // jump link of the browser address
If (Action = haction ){
$ (Item). Parents ("Li"). addclass ("On"). siblings (). removeclass ("On ");
}
}
}
});
});