本文主要介绍了jquery实现导航栏头部菜单项点击后变换颜色的方法,涉及jquery响应鼠标事件针对页面元素的遍历及属性变换相关操作技巧,需要的朋友可以参考下,希望鞥帮助到大家。
实现效果如下:


话不多说直接上代码:
<!DOCTYPE html>
<html>
<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 href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首页</a></li>
<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >直播</a></li>
<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >新闻</a></li>
<li><a 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实现导航栏头部菜单项点击后变换颜色的方法实例详解的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号