我希望我的下拉链接突出,但也在顶部的下拉链接。如果您查看http://rezolve.4pixels.com/banks-and-telcos/home/banks-and-telcos.php,然后单击任何下拉列表中的最后一个链接,它们就会完美地工作(它们突出显示自己的“li”和父“li”)。我只是不明白为什么每个下拉列表中只有最后一个链接才能做我想做的事情(除了最后一个之外,其他的都不做)。我原以为“父母”会把所有的祖先“李”接起来
我的剧本是:
$(document).ready(function(){
"use strict";
var currentPageUrl = location.href;
$('.nk-nav li a').each(function(){
$(this).parents("li").toggleClass('active', this.href === currentPageUrl);
});
});发布于 2017-04-03 00:40:22
我不知道为什么“部分”有效..。
我不认为是因为你的剧本。
您会注意到,console.log(currentPageUrl);返回完整地址。
(包括http://rezolve.4pixels.com/)。
您的脚本将其与相对URL进行比较。
(没有http://rezolve.4pixels.com/)
,所以它不能经常匹配。
所以我建议你试试.
$(document).ready(function(){
"use strict";
var currentPageUrl = location.href;
console.log(currentPageUrl);
$('.nk-drop-item').find('a').each(function(){
if( "http://rezolve.4pixels.com"+ $(this).attr("href") === currentPageUrl ){
$(this).closest(".nk-drop-item").addClass('active');
}
});
});但我不知道是否会有干扰。
https://stackoverflow.com/questions/43172441
复制相似问题