[英]Snippet works on Chrome, Safari but not on Firefox
Added this bit of code to highlight active page in menu using Jquery 3.3.1 and it works on Chrome and Safari but not on Firefox. 添加了这段代码,以使用Jquery 3.3.1突出显示菜单中的活动页面,并且它在Chrome和Safari上有效,但在Firefox上无效。 Using a local version of Jquery.min.js and cleared cache but still not working. 使用本地版本的Jquery.min.js并清除了缓存,但仍然无法正常工作。
$(document).ready(function(){
$('a').each(function() {
if ($(this).prop('href') == window.location.href) {
$(this).addClass('current');
}
});
});
String comparison is case sensitive.. I think you can try these two methods to see if they work.. 字符串比较区分大小写。.我认为您可以尝试这两种方法来查看它们是否有效。
First: Use a toLowerCase method 第一:使用toLowerCase方法
$(document).ready(function(){
$('a').each(function() {
if ($(this).prop('href').toLowerCase() == window.location.href.toLowerCase()) {
$(this).addClass('current');
}
});
});
Second: Console output what the browsers are seeing 第二:控制台输出浏览器看到的内容
$(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');
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.