我制作了一个下拉菜单,它使用选项卡来显示每个菜单项的特定内容。
这是我用于标签功能的 jQuery 教程的链接: http ://www.jacklmoore.com/notes/jquery-tabs
我已经修改了代码以满足我的需要,但是我无法找到一种方法来更改也应用了“活动”类的元素。出于 CSS 样式的原因,我希望将“活动”类应用于当前正在添加的父<li>
类。<a>
我尝试了各种解决方案,包括该.parent();
方法无济于事。这里的任何建议将不胜感激。
这是处理添加类的代码的快速片段:
// Keep track of which tab is active and it's associated content
var $active, $content, $links = $(this).find('li.activate-dropdown a');
// If the location.hash matches one of the links, use that as the active tab.
$active = $($links.filter('[rel="'+location.hash+'"]')[0]);
$active.addClass('active');
$content = $($active.attr('rel'));
编辑: 示例实时代码 - http://jsfiddle.net/jgfg7/3/