发布时间:2020-11-07
html:
jquery:
//除了首页外当前URL对当前栏目高亮突出显示
$(".nav li a:not(:first)").each(function(){
$this = $(this);
if($this[0].href==String(window.location)){
$this.parent().addClass("selected");
}
});
//当前URL对当前栏目高亮突出显示
$(".sidenav li a").each(function(){
$this = $(this);
if($this[0].href==String(window.location)){
$this.parent().addClass("selected");
}
});
或者原生js:
//js 当前URL对当前栏目高亮突出显示
var myNav = document.getElementById("nav").getElementsByTagName("a");
for(var i=0;i
var myURL = document.location.href;
if(myURL.indexOf(links) != -1){
myNav[i].parentNode.className="selected";
}
}
全站搜索