Jquery controls template menu styles

Source: Internet
Author: User

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 ");
}
}
}
});
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.