The JavaScript navigation script judges the current navigation

  • 2021-07-02 23:16:32
  • OfStack

Don't say much nonsense, just post the code for everyone.


<script>
$(function () {
//highlight current / active link  The left navigation judges the current active navigation 
$('ul.main-menu li a').each(function () {
var wo = window.location.href.substring(window.location.href.lastIndexOf('/') + 1, window.location.href.lastIndexOf('.'));
if ($(this).attr('href') == (wo + ".html")) {
$(this).parent().addClass('active');
$(this).parents().addClass('active');
$(this).parents('li').find("i:first").toggleClass("glyphicon-minus");
$(this).parents('ul').slideDown();
}else
if (("dxs" == wo || "syd" == wo)&&($(this).attr('href')=="dbs.html")) {
$(this).parent().addClass('active');
$(this).parents().addClass('active');
$(this).parents('li').find("i:first").toggleClass("glyphicon-minus");
$(this).parents('ul').slideDown();
}
});
/*** begin  Homepage Left Menu  */ 
$(".main-menu a").click(function () {
// Will the current li Set to active state 
$(this).find("i:first").toggleClass("glyphicon-minus");
});
$(".main-menu a").click(function () {
// Replace the addition and subtraction icon of other navigation 
$(this).parent('li').siblings(".active").find("i:first").toggleClass("glyphicon-minus");
//alert($(this).index());
// Remove the click style of other navigation and collapse it 
$(this).parent('li').siblings(".active").removeClass("active").children("ul").slideUp('fast');
$(this).next('ul').slideToggle('fast');
$(this).parent('li').addClass('active');
});
/************** end  Homepage Left Menu  */
})
</script>

Related articles: