<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .box{ width:440px; border:1px solid #000000; margin: 100px auto; padding: 10px; } .hd{ overflow: hidden; } .hd span{ float: left; margin-right: 10px; width: 100px; height: 30px; background-color: #ccc; } .hd span.current{ background-color: deeppink; } .bd div{ width: 440px; height: 300px; background-color: deeppink; display: none; } </style> <script type="text/javascript" src="jquery-1.11.3.min.js"></script> <script> $(function () { $('.hd span').mouseenter(function () { //sibling兄弟,siblings兄弟们 //被鼠标经过的哪一个属性变为current,其他的class为空 $(this).attr('class','current').siblings().attr('class',''); //选择符合元素索引号的那个显示出来,其他兄弟们隐藏 $('.bd div').eq($(this).index()).show().siblings().hide(); }) }) </script> </head> <body> <div class="box"> <div class="hd"> <span class="current">新闻</span> <span>体育</span> <span>娱乐</span> <span>财经</span> </div> <div class="bd"> <div style="display: block">新闻</div> <div>体育</div> <div>娱乐</div> <div>财经</div> </div> </div> </body> </html>
jQuery Tab栏切换
最新推荐文章于 2021-02-05 23:47:05 发布