我的菜单显示除了主页链接(http://www.obsia.com)之外的其他链接时的活动链接。它从未被强调。 我试着玩,但我似乎无法弄清楚。这是我用来突出链接的jQuery代码?菜单上的主页链接不突出显示
$(function(){
var path = location.pathname.substring(1);
if (path)
$('.nav a[href$="' + path + '"]').attr('class', 'active');
});
我也对products pages另一个菜单,在这里我想强调的兄弟姐妹的父母和我们的产品在全球的菜单上。这是产品菜单的jQuery代码:
$(function() {
var pathname = location.pathname;
var highlight;
//highlight home
if(pathname == "")
highlight = $('ul#accordion > li:first > a:first');
else {
var path = pathname.substring(1);
if (path)
highlight = $('ul#accordion a[href$="' + path + '"]');
}highlight.attr('class', 'active');
// hide 2nd, 3rd, ... level menus
$('ul#accordion ul').hide();
// show child menu on click
$('ul#accordion > li > a.product_menu').click(function() {
//minor improvement
$(this).siblings('ul').toggle("slow");
return false;
});
//open to current group (highlighted link) by show all parent ul's
$('a.active').parents('ul').show();
$('a.active').parents('h2 a').css({'color':'#ff8833'});
//if you only have a 2 level deep navigation you could
//use this instead
//$('a.selected').parents("ul").eq(0).show();
}); });
我尝试添加此:
$(this).parents('ul').addClass('active');
,但似乎并没有这样的伎俩?
有没有人有一个简单的方法来完成它? 任何帮助,将不胜感激你们。
亲切的问候, 摹
谢谢斯蒂芬的工作 - 我甚至把括号上的第一条if语句以及:) – strangeloops 2010-03-16 13:54:54
其实只是再次检查,即使在主页上使用更正的代码后,我得到高亮未定义的错误?难道我做错了什么? – strangeloops 2010-03-16 16:32:02
其实只是修复它,谢谢:) – strangeloops 2010-03-16 16:41:08