养成好习惯是储存健康,放纵不良是透支生命。我们一生之中,要牢记和要忘记的东西一样多。
本文实例讲述了jQuery实现导航栏头部菜单项点击后变换颜色的方法。分享给大家供大家参考,具体如下:
实现效果如下:
话不多说直接上代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
a{
text-decoration: none;
color: black;
}
#menu{
width: 100%;
height: 20px;
background: gainsboro;
}
ul li{
list-style: none;
float: left;
padding-left: 20px;
background-color: whitesmoke;
}
.active {
color: white;
background-color: black;
}
.none {
background-color: whitesmoke;
}
</style>
</head>
<body>
<ul id="menu">
<li><a rel="nofollow noopener noreferrer" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首页</a></li>
<li><a rel="nofollow noopener noreferrer" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >直播</a></li>
<li><a rel="nofollow noopener noreferrer" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >新闻</a></li>
<li><a rel="nofollow noopener noreferrer" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >关于</a></li>
</ul>
<script src="jquery-1.7.2.min.js"></script>
<script>
$('#menu li a').click(function () {
var f = this;
$('#menu li a').each(function () {
this.className = this == f ? 'active' : 'none'
});
});
</script>
</body>
</html>
希望本文所述对大家jQuery程序设计有所帮助。
以上就是jQuery实现导航栏头部菜单项点击后变换颜色的方法。生活不可能一帆风顺,总会有波折,总会有险阻,生活是个爱开玩笑的孩子,也许今天给你所有,明天又会让你一无所有,无需烦恼,该来的总会来,再黑的夜晚也会有黎明到来的那一刻,不管生活有多么曲折,只要拥有幸福的态度就能挺过漫漫长夜,就能迎来美好的明天。更多关于jQuery实现导航栏头部菜单项点击后变换颜色的方法请关注haodaima.com其它相关文章!




