1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html> 
  3.     <head> 
  4.         <meta http-equiv="content-type" content="text/html;charset=utf-8"/> 
  5.         <meta name="keywords" content="关键词1,关键词2,关键词3等等"/> 
  6.         <title>网页选项卡</title> 
  7.         <style type="text/css"> 
  8.             body,ul,li{margin:0; padding:0; list-style:none;} 
  9.             .wrap{width:300px; height:200px; margin:10px auto; border:1px solid #000; padding:10px;} 
  10.             .tab_menu{clear:both; margin-top:10px;} 
  11.             .tab_box{clear:both;} 
  12.             ul li{float:left; width:60px; height:30px; line-height:30px; text-align:center; margin-right:10px; pink;} < /span>
  13.             .selected{background:#999;} 
  14.             .tab_box div{height:150px; border:1px solid #f00;} 
  15.             .hid{display:none;} 
  16.             .hover{background:#f00;} 
  17.         </style> 
  18.         <script type="text/javascript" src="jquery-1.7.2.min.js"></script> 
  19.         <script type="text/javascript"> 
  20.             $(function(){ 
  21.                 var $div_li=$("div.tab_menu ul li"); 
  22.                 $div_li.click(function(){ 
  23.                     $(this).addClass("selected") 
  24.                            .siblings().removeClass("selected"); 
  25.                     var index=$div_li.index(this);//获取当前单击的li在全部li中的索引 
  26.                     $("div.tab_box>div") 
  27.                            .eq(index).show()   //显示li元素对应的div元素 
  28.                            .siblings().hide(); 
  29.                 }).hover(function(){//添加鼠标划入划出效果 
  30.                     $(this).addClass("hover"); 
  31.                 },function(){ 
  32.                     $(this).removeClass("hover"); 
  33.                 }) 
  34.             }) 
  35.         </script> 
  36.     </head> 
  37.     <body> 
  38.         <div class="wrap"> 
  39.             <div class="tab_menu"> 
  40.                 <ul> 
  41.                     <li class="selected">时事</li> 
  42.                     <li>体育</li> 
  43.                     <li>娱乐</li> 
  44.                 </ul> 
  45.             </div> 
  46.             <div class="tab_box"> 
  47.                 <div>时事</div> 
  48.                 <div class="hid">体育</div> 
  49.                 <div class="hid">娱乐</div> 
  50.             </div> 
  51.         </div> 
  52.     </body> 
  53. </html>