我有产品的全局菜单和本地菜单。我想在显示产品时突出显示“我们的产品”链接,并在本地菜单中突出显示产品名称及其子页面,以便突出显示的链接将用作面包屑。如何使用 jquery 和 codeigniter 或仅使用 jquery 来做到这一点。这是本地菜单的代码:
<ul id="accordion">
<li class="pm"><h2><?php echo anchor('/products/thassos_wonder', 'Thassos Wonder+');?></h2>
<ul class="product_menu">
<h2><?php echo anchor('/products/thassos_wonder', 'Thassos Wonder+');?></h2>
<h2><?php echo anchor('/products/thassos_wonder_advantages', 'Thassos Wonder+ Advantages');?></h2>
<h2><?php echo anchor('products/thassos_wonder_associated_products', 'Associated Products');?></h2>
<h2><?php echo anchor('/products/thassos_wonder_brochure', 'Download TW+ Brochure');?></h2>
</ul>
</li>
<li class="pm"><h2><?php echo anchor('/products/marble_wonder', 'Marble Wonder+');?></h2>
<ul class="product_menu" id="mwmenu">
<h2><?php echo anchor('/products/marble_wonder', 'Marble Wonder+');?></h2>
<h2><?php echo anchor('/products/marble_wonder_advantages', 'Marble Wonder+ Advantages');?></h2>
<h2><?php echo anchor('products/marble_wonder_associated_products', 'Associated Products');?></h2>
<h2><?php echo anchor('/products/marble_wonder_brochure', 'Download MW+ Brochure');?></h2>
</ul>
</li>
<li class="pm"><h2><?php echo anchor('/products/polybond', 'Poly Bond+');?></h2>
<ul class="product_menu" id="pbmenu">
<h2><?php echo anchor('/products/polybond', 'Poly Bond+');?></h2>
<h2><?php echo anchor('/products/polybond_advantages', 'PolyBond+ Advantages');?></h2>
<h2><?php echo anchor('products/polybond_areas_of_applications', 'Areas of Applications');?></h2>
<h2><?php echo anchor('/products/polybond_brochure', 'Download Polybond+ Brochure');?></h2>
</ul>
</li>
这是本地菜单的jquery代码:
$(function() {
var pathname = location.pathname;
var highlight;
//highlight home
if(pathname == "/"){
highlight = $('ul#accordion > li:first > a:first');
$('a.active').parents('li').addClass('active');
}
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();
//if you only have a 2 level deep navigation you could
//use this instead
//$('a.selected').parents("ul").eq(0).show();
});
仍在学习 jquery,因此将不胜感激。谢谢 - G