使用Jquery 3.3.1添加了这段代码来突出显示菜单中的活动页面,它可以在Chrome和Safari上运行,但不能在Firefox上运行。正在使用Jquery.min.js的本地版本并清除了缓存,但仍无法工作。
$(document).ready(function(){
$('a').each(function() {
if ($(this).prop('href') == window.location.href) {
$(this).addClass('current');
}
});
});
发布于 2018-12-01 01:13:02
字符串比较区分大小写。我想你可以试试这两种方法,看看它们是否有效。
首先:使用toLowerCase方法
$(document).ready(function(){
$('a').each(function() {
if ($(this).prop('href').toLowerCase() == window.location.href.toLowerCase()) {
$(this).addClass('current');
}
});
});
第二:控制台输出浏览器所看到的内容
$(document).ready(function(){
$('a').each(function() {
console.log("href : " + $(this).prop('href'));
console.log("window.location.href : " + window.location.href);
if ($(this).prop('href').toLowerCase() == window.location.href.toLowerCase()) {
$(this).addClass('current');
}
});
});
https://stackoverflow.com/questions/53561916
复制相似问题