如何仅突出显示所选菜单项和其他菜单项的默认值 [英] how to highlight only selected menu item and default for others
本文介绍了如何仅突出显示所选菜单项和其他菜单项的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个垂直菜单,如:
I have a vertical menu like:
<nav>
<ul>
<li><a></a></li>
<li><a></a></li>
<li><a></a></li>
</ul>
</nav>
并为bg-color制作了2个类:默认,选中
我想将选定类应用于新选择的项目,并获得旧的或上一个选择的项目默认类
css:
.defaultBg {background-color:white; }
。选择{background-color:blue; }
如何在点击链接标记
and made 2 classes for bg-color: default , selected
I want to apply "selected" class to the newly selected item and get the older or previousely selected item "default" class
css:
.defaultBg{ background-color: white; }
.selected{ background-color: blue; }
How can i assign this classes to those list items respectively with jquery when clicking on link tag
<a></a>
在其中
推荐答案
您可能不需要标签,因为标签的默认值是跟随链接。您可以阻止默认操作发生,但为什么在不使用时添加 元素。
此外它非常简单:
You may not want the tag, because the default for an a tag is to follow a link. You can prevent the default action from occuring, but why adding the element if you don't use it.
Further it's quite simple :
( document )。ready({ function (){
(document).ready({ function(){
( li)。click( function (e){
// 点击LI
// 将所有其他li设置为未选中
("li").click(function(e){ // A LI is clicked // Set all other li's to not selected
这篇关于如何仅突出显示所选菜单项和其他菜单项的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文