tab标签(选项卡)切换实现

 
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head lang="en">  
  4.     <meta charset="UTF-8">  
  5.     <title></title>  
  6.     <script type="text/javascript">  
  7.         //导航栏单击变换内容  
  8.         function tabSwitch(_this,num) {  
  9.             var tag = document.getElementById("nav9");  
  10.             var number = tag.getElementsByTagName("a");   //获取导航栏元素个数(getElementsByTagName是返回元素素组)  
  11.             var divNum = document.getElementsByClassName("eachDiv");   //获取导航元素对应的div个数  
  12.             for(var i=0;i<number.length;i++){    //number是一个数组,这里应该用number.length显示它的长度5  
  13.                 number[i].className = " ";   //清除所有导航栏元素的特殊样式  
  14.                 divNum[i].style.display = "none";   //其他所有div都隐藏  
  15.             }  
  16.             _this.className = "l_nav1_no1";  //给当前导航栏元素添加样式  
  17.             var content = document.getElementById("l_no2_"+num);  //当前导航栏元素对应的div  
  18.             content.style.display = "block";  //显示当前导航栏元素对应的div部分  
  19.         }  
  20.     </script>  
  21.     <style type="text/css">  
  22.         .l_nav1 {  
  23.             height: 30px;  
  24.             padding-top: 8px;  
  25.         }  
  26.         .l_nav1 a{  
  27.             color: #3C3C3C;  
  28.             text-decoration: none;  
  29.             padding: 8px;  
  30.         }  
  31.         .l_nav1 a:hover,#l_nav1 a:active {  
  32.             color: green;  
  33.             text-decoration: underline;  
  34.         }  
  35.         .l_nav1 .l_nav1_no1 {   /*“头条”*/  
  36.             color: green;  
  37.             text-decoration: none;  
  38.             border-top: solid 1px green;  
  39.         }  
  40.   
  41.         .l_no2 {  
  42.             background-color: #ffffff;  
  43.             border: solid 1px #E0E0E0;  
  44.             height: 282px;  
  45.             width: 276px;  
  46.             overflow: scroll;   /*当元素内容太大而超出规定区域时,内容会被修剪,但是浏览器会显示滚动条以便查看其余的内容。。*/  
  47.         }  
  48.         .l_no2 ul{     /*列表部分*/  
  49.             padding-left: 0px;  
  50.             line-height: 25px;  
  51.             font-size: 14px;;  
  52.         }  
  53.         .l_no2 ul li{  
  54.             list-style: none;  
  55.         }  
  56.         .l_no2 ul a{  
  57.             color: #3C3C3C;  
  58.             text-decoration: none;  
  59.         }  
  60.         .l_no2 ul a:active,.l_no2 ul a:hover {  
  61.             color: red;  
  62.             text-decoration: underline;  
  63.         }  
  64.     </style>  
  65. </head>  
  66. <body>  
  67.     <nav id="nav9" class="l_nav1">  
  68.         <href="#"  οnclick="tabSwitch(this,1)" class="l_nav1_no1">头条</a>  
  69.         <href="#"  οnclick="tabSwitch(this,2)">社会</a>  
  70.         <href="#"  οnclick="tabSwitch(this,3)">娱乐</a>  
  71.         <href="#"  οnclick="tabSwitch(this,4)">军事</a>  
  72.         <href="#"  οnclick="tabSwitch(this,5)">体育</a>  
  73.     </nav>  
  74.     <div class="l_no2">  
  75.         <div id="l_no2_1" class="eachDiv" style="display: block">   <!--默认为该div显示-->  
  76.             <img src="http://www.pp3.cn/uploads/allimg/111110/15563RI9-7.jpg" width="274px">  
  77.             <ul>  
  78.                 <li><strong style="color: #6C6C6C"</strong><href="#">县领导找不着住建局长 对其通报批评</a></li>  
  79.                 <li><strong style="color: #6C6C6C"</strong><href="#">科级干部受贿近亿 庭上力保妻子清白</a></li>  
  80.                 <li><strong style="color: #6C6C6C"</strong><href="#">儿子将老母接回家享福 老人悬绳自尽</a></li>  
  81.                 <li><strong style="color: #6C6C6C"</strong><href="#">女子亲热感觉"卡" 检查现"异形"侵体</a></li>  
  82.                 <li><strong style="color: #6C6C6C"</strong><href="#">大妈被女童玩具小车撞到 叫来救护车</a></li>  
  83.                 <li><strong style="color: #6C6C6C"</strong><href="#">六旬老人遇老相识 30元发生关系被抓</a></li>  
  84.             </ul>  
  85.         </div>  
  86.         <div id="l_no2_2" class="eachDiv" style="display: none">  
  87.             <img src="http://www.pp3.cn/uploads/allimg/111110/114J0L31-5.jpg" width="274px">  
  88.             <ul>  
  89.                 <li><strong style="color: #6C6C6C"</strong><href="#">捐精男与受精女一见钟情 孩子已1岁</a></li>  
  90.                 <li><strong style="color: #6C6C6C"</strong><href="#">妻子产子收1200枚鸡蛋 丈夫1天卖光</a></li>  
  91.                 <li><strong style="color: #6C6C6C"</strong><href="#">男子为同房说尽好话仍遭拒 残忍杀妻</a></li>  
  92.                 <li><strong style="color: #6C6C6C"</strong><href="#">母猪产下八名男婴 原因竟然如此凄凉</a></li>  
  93.                 <li><strong style="color: #6C6C6C"</strong><href="#">小夫妻宾馆开房 隔壁大叔全程看直播</a></li>  
  94.                 <li><strong style="color: #6C6C6C"</strong><href="#">老汉自造房车囚禁两妙龄女 边走边玩</a></li>  
  95.             </ul>  
  96.         </div>  
  97.         <div id="l_no2_3" class="eachDiv" style="display: none">  
  98.             <img src="http://photo.enterdesk.com/2011-2-16/enterdesk.com-1AA0C93EFFA51E6D7EFE1AE7B671951F.jpg" width="274px">  
  99.             <ul>  
  100.                 <li><strong style="color: #6C6C6C"</strong><href="#">金星追问陈坤儿子生母 他还真招认了</a></li>  
  101.                 <li><strong style="color: #6C6C6C"</strong><href="#">贾静雯说“我又怀孕了”真相被曝光</a></li>  
  102.                 <li><strong style="color: #6C6C6C"</strong><href="#">抽烟喝酒后 成龙17岁私生女变成这样</a></li>  
  103.                 <li><strong style="color: #6C6C6C"</strong><href="#">台湾女星“酒后乱性” 婆婆当场傻眼</a></li>  
  104.                 <li><strong style="color: #6C6C6C"</strong><href="#">车晓和前夫离婚后 如此评价这段经历</a></li>  
  105.                 <li><strong style="color: #6C6C6C"</strong><href="#">韩国卖淫女星身份遭曝光!G.NA在列</a></li>  
  106.             </ul>  
  107.         </div>  
  108.         <div id="l_no2_4" class="eachDiv" style="display: none">  
  109.             <img src="http://h.hiphotos.baidu.com/zhidao/pic/item/6a63f6246b600c3320b14bb3184c510fd8f9a185.jpg" width="274px">  
  110.             <ul>  
  111.                 <li><strong style="color: #6C6C6C"</strong><href="#">朝鲜愤然击落美军侦察机 美为何认怂</a></li>  
  112.                 <li><strong style="color: #6C6C6C"</strong><href="#">多数人不知道 中国已经买过四艘航母</a></li>  
  113.                 <li><strong style="color: #6C6C6C"</strong><href="#">还敢逮捕中国渔民?印尼外长开口求饶</a></li>  
  114.                 <li><strong style="color: #6C6C6C"</strong><href="#">揭秘辽宁舰上首位女军官 履历太吓人</a></li>  
  115.                 <li><strong style="color: #6C6C6C"</strong><href="#">中国两栖登陆王牌协同作战 场面壮观</a></li>  
  116.                 <li><strong style="color: #6C6C6C"</strong><href="#">朝鲜惊人作战计划曝光:突袭朴槿惠</a></li>  
  117.             </ul>  
  118.         </div>  
  119.         <div id="l_no2_5" class="eachDiv" style="display: none">  
  120.             <img src="http://www.pp3.cn/uploads/allimg/111111/0955412061-6.jpg" width="274px">  
  121.             <ul>  
  122.                 <li><strong style="color: #6C6C6C"</strong><href="#">末战胜卡塔尔不够 国足期待2队犯错</a></li>  
  123.                 <li><strong style="color: #6C6C6C"</strong><href="#">赛中产子属误传 产妇是辽宁女排队员</a></li>  
  124.                 <li><strong style="color: #6C6C6C"</strong><href="#">球迷50万赌国足赢4球以上 血本无归</a></li>  
  125.                 <li><strong style="color: #6C6C6C"</strong><href="#">高洪波:国足只能算一般队 比较命苦</a></li>  
  126.                 <li><strong style="color: #6C6C6C"</strong><href="#">段江鹏将投北京队 下赛季联手马布里</a></li>  
  127.                 <li><strong style="color: #6C6C6C"</strong><href="#">白人小伙风骚表演 全程开启库里模式</a></li>  
  128.             </ul>  
  129.         </div>  
  130.     </div>  
  131. </body>  
  132. </html>  

转载于:https://www.cnblogs.com/songfayuan/articles/7290337.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值