给导航条设置高亮显示,但是在含有同步分页时,会碰到无法高亮问题
导航条高亮显示用
if ($($(this))[0].href == String(window.location)) {}
或者
if(this.href==window.location.href){}
(在方法体内加入样式切换)这两种方式都可以做到
若想同步分页,点击下一页时,同样高亮显示则去比对两个URL相同部分,截掉后缀不相同的部分则可实现
具体代码示例如下:
$(".navbar li>a").each(function() {
var str=this.href;
str=str.substr(0,str.lastIndexOf("&"));
var str1=window.location.href;
str1=str1.substr(0,str1.lastIndexOf("&"));
//if ($($(this))[0].href == String(window.location)) {
//if(this.href==window.location.href){
if(str==str1){
$(this).parent().addClass("current");
var index = $(".navbar li>a").index(this);
$(".section_top_image").attr("src","img/topImage_"+index+".jpg");
}
});