This article mainly introduces how to activate the current page navigation using javascript. it involves javascript operations on css and has some reference value, for more information about how to activate the current page navigation using javascript, see the following example. Share it with you for your reference. The details are as follows:
Html section (reference navigation, unavailable # Replace link, test how to create several static pages)
- Homepage
- HTML/CSS
- JavaScript
- SEO
- Front-end news
Javascript section (add the. on class to the specified navigation on the current page)
$(function() {var a1 = document.URL;var a2 = $("#nav a");for (var i = 0; i < a2.length; i++) {if (a1.indexOf($(a2[i]).attr("href")) != -1) {$(a2[i]).parent().addClass("on");return;}}$(a2[0]).parent().addClass("on");})
Css section (you can adjust it based on your needs)
#nav li{display:inline-block;float:left;text-align:center;height:36px;padding-left:4px;line-height:36px;background:url(images/nav.gif) no-repeat right bottom;}#nav li a{display:block;color:#777;padding:0 15px 0 10px;}#nav li.on{font-weight:bold;background:url(images/nav.gif) no-repeat 0 0;margin-left:-3px;}#nav li.on a{background:url(images/nav.gif) no-repeat right 0;}
I hope this article will help you design javascript programs.