本文实例讲述了jQuery实现的导航条点击后高亮显示功能。分享给大家供大家参考,具体如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.haodaima.com jQuery导航条点击后高亮显示</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <style> #nav li {float: left; width: 80px; text-align: center; list-style-type: none;} .nav-active {background: #ff47a5;} .nav-active a {color: #fff;text- decoration:none} </style> </head> <body> <ul id="nav"> <li class="nav-active"><a rel="nofollow noopener noreferrer" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首页</a></li> <li><a rel="nofollow noopener noreferrer" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Page1</a></li> <li><a rel="nofollow noopener noreferrer" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Page2</a></li> <li><a rel="nofollow noopener noreferrer" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Page3</a></li> <li><a rel="nofollow noopener noreferrer" href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Page4</a></li> </ul> <script> $('#nav').find('li').click(function() { // 为当前点击的导航加上高亮,其余的移除高亮 $(this).addClass('nav-active').siblings('li').removeClass('nav-active'); }); </script> </body> </html>
使用在线HTML/CSS/JavaScript代码运行工具:http://tools.haodaima.com/code/HtmlJsRun测试上述代码,运行效果如下:
希望本文所述对大家jQuery程序设计有所帮助。
以上就是jQuery实现的导航条点击后高亮显示功能示例。才情,是女人找求成功的本钱,由着此她想要一切。有点才情的女人,常常活得不幸福。更多关于jQuery实现的导航条点击后高亮显示功能示例请关注haodaima.com其它相关文章!