javascript - 如何根据点击将 "mark"一个 UL/LI 导航项作为 "active"?

标签 javascript jquery html css

每个<a链接是 jQuery 隐藏(显示)某些 div 的 anchor 。

我正在使用这个 CSS 来处理悬停样式:

ul.textMenu a:hover

{   
    border-bottom: 3px solid #ff5c00;
    margin-bottom: -3px;
}

用户点击一个元素后,我想要那个 border-bottom坚持。我该怎么做?

menu

最佳答案

添加一个CSS规则

ul.textMenu a.clicked

{   
    border-bottom: 3px solid #ff5c00;

}

然后是一些js

$('ul.textMenu a').click( function() {
    // Remove the class clicked so that we have only one clicked item
    // Since there might be more than one ul i finde the parent.
    $(this).closest('ul.textMenu').find('a').removeClass('clicked')
    $(this).addClass('clicked');
} );

关于javascript - 如何根据点击将 "mark"一个 UL/LI 导航项作为 "active"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13146137/

相关文章:

javascript - 将默认焦点设置在不是第一个的特定下拉选项上?

javascript - jQuery 从字符串 block 中删除行的问题

javascript - 在选择更改 Struts2 时更新表单

javascript - JavaScript 中的小数到分数

php - 将重新排序的列表的顺序提交到我的服务器

html - html中的空格选择选项

html - 即使在 html/css 中调整页面大小时如何将文本保持在屏幕中间

javascript - JS slider 菜单切换问题

javascript - 使用 jQuery 添加元素后刷新 css

javascript - vue 的 .each() 方式