我的菜单在单击时会显示活动链接,但主页链接 ( http://www.obsia.com ) 除外。它从不突出显示。我试着到处玩,但我似乎无法弄清楚。这是我用来突出显示链接的 jquery 代码?
$(function(){
var path = location.pathname.substring(1);
if ( path )
$('.nav a[href$="' + path + '"]').attr('class', 'active');
});
我在产品页面上还有另一个菜单,我想在全局菜单中突出显示兄弟姐妹的父母和我们的产品。这是产品菜单的 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');
但这似乎不起作用?
有没有人有一个简单的方法来完成它?任何帮助将不胜感激你们。
亲切的问候,G