jquery tab选项卡切换收集
1、带渐显效果的选项卡菜单
附件如下。
注:不建议修改成:onmouseover事件
2、纯js的tab,鼠标移动切换
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
- <style>
- <!--
- html{
- margin:0px;
- padding:0px;
- }
- body{
- font-family:'宋体', Arial;
- margin:0px;
- padding:0px;
- color:#155380;
- font-size:12px;
- background:#ccc;
- }
- .wai{
- border:0px solid #f00;
- height:41px;
- width:231px;
- margin-left:0px;
- padding:0px;
- font-size:14px;
- line-height:41px;
- color:#fff;
- padding-left:8px;
- background:#360;
- position:relative;
- }
- #menu{
- border:0px solid #fff;
- width:85px;
- height:30px;
- margin:0px;
- padding:0px;
- position:absolute;
- top:8px;
- right:10px;
- }
- #menu div{
- border:0px solid #00f;
- width:27px;
- height:30px;
- line-height:30px;
- float:left;
- font-family:宋体;
- font-weight:lighter;
- font-size:14px;
- margin:0px;
- cursor:pointer;
- text-align:center;
- background:url(images/box_blue.jpg) no-repeat;
- }
- #menu .over{
- border-bottom:0px solid #f00;
- background:url(images/box.jpg) no-repeat;
- color:#153380;
- font-family:宋体;
- font-size:14px;
- font-weight:lighter;
- }
- -->
- </style>
- </head>
- <body>
- <div class="wai">排行榜<div id="menu"><div>总</div><div>周</div><div>月</div></div></div>
- <div id="sub">
- <div class="submenu">
- 11111111111
- </div>
- <div class="submenu">
- 222222222
- </div>
- <div class="submenu">
- 3333333333
- </div>
- </div>
- <script>
- function $(id){return document.getElementById(id)}
- var menu_id="menu"//标签ID
- var submenu_id="sub"//子标签ID
- t=$(menu_id).getElementsByTagName("div");//所有的menu
- tt=$(submenu_id).getElementsByTagName("div");
- var s= new Array();
- for(i=0;i<tt.length;i++){
- if(tt[i].parentNode.id==submenu_id){
- s.push(tt[i])//将参数添加到原数组末尾
- }
- }
- //s=$(submenu_id).childNodes;
- for(i=0;i<t.length;i++){
- if(document.all){//IE
- var cc= function(i){
- return function(){
- abc(i)
- };
- };
- t[i].attachEvent("onmouseover",cc(i));
- }
- else{//ff
- t[i].setAttribute("onmouseover","abc("+i+")");
- }
- }
- function abc(i){
- for(j=0;j<t.length;j++)t[j].className=''//让所有的按钮变暗
- t[i].className='over'//让自己亮
- for(j=0;j<s.length;j++)s[j].style.display='none'//让所有框消失
- s[i].style.display='block';
- }
- abc(0);//初始状态
- </script>
- </body>
- </html>
附件:http://down.51cto.com/data/2361484
本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/1001704,如需转载请自行联系原作者