JS实现的tab切换选项卡效果示例


Posted in Javascript onFebruary 28, 2017

本文实例讲述了JS实现的tab切换选项卡效果。分享给大家供大家参考,具体如下:

<script type="text/javascript">
/*
tab切换选项卡js效果   writed by *** 2010.08.13
1.currentid:string 当前被激活菜单的id;
2.otherids:Array() 其它未被激活的id;
3.tabclasses:Array() tab被激活时的样式类+tab未被激活时的样式类,存储两个值即可
*/
function chaneTab(currentid,otherids,tabclasses){
  var tagPrefix="tab";
  var conPrefix="con";
  //显示:
  document.getElementById(tagPrefix+currentid).className=tabclasses[0];
  document.getElementById(conPrefix+currentid).style.display="block";
  //隐藏:
  for(var i=0;i<otherids.length;i++){
    document.getElementById(tagPrefix+otherids[i]).className=tabclasses[1];
    document.getElementById(conPrefix+otherids[i]).style.display="none";
  }
}
</script>

应用代码:

<div class="right_centerzbt ml10">
   <div class="tou">
    <ul class="mt50">
      <li onmouseover="chaneTab('001',new Array('002'),new Array('center_bj',''))" id="tab001" class="center_bj"><a>名山明星榜</a></li>
      <li onmouseover="chaneTab('002',new Array('001'),new Array('center_bj',''))" id="tab002"><a>热门群组</a></li>
    </ul>
   </div>
  <div id="con001" style="display: block;" class="right_content1 l bl br bb">
      <iframe width="680" height="391" frameborder="0" scrolling="no" style="margin-left: -1px;" border="0" marginheight="0" marginwidth="0" src="shequ/uchome/do.php?ac=ajax&op=getindexspace"></iframe>   
  </div>
  <div id="con002" style="display: none;" class="right_content1 l bl br bb">
          <ol class="mt10 ml10">
    <li class="quanzi_pic ml10"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=23" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img onerror="this.onerror=null;this.src='';" src="http://192.168.0.113/shequ/uchome/upload/2010-08/128142654112531.jpg"></a></li>
    <li class="ml5"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=23" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><b>武林英雄官方群</b></a>(今日:<span><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=23" rel="external nofollow" rel="external nofollow" rel="external nofollow" >0</a></span>)</li>
    <li class="ml5"></li>
    <li class="ml5">主题:<span>0</span>,贴数:<span>0</span></li>
   </ol>
          <ol class="mt10 ">
    <li class="quanzi_pic ml10"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=14" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img onerror="this.onerror=null;this.src='';" src="http://192.168.0.113/shequ/uchome/upload/2010-08/128142678521940.jpg"></a></li>
    <li class="ml5"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=14" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><b>游戏贴图</b></a>(今日:<span><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=14" rel="external nofollow" rel="external nofollow" rel="external nofollow" >0</a></span>)</li>
    <li class="ml5">这里是维客分享与会员互动区。您的...</li>
    <li class="ml5">主题:<span>0</span>,贴数:<span>0</span></li>
   </ol>
          <ol class="mt10 ml10">
    <li class="quanzi_pic ml10"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=20" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img onerror="this.onerror=null;this.src='';" src="http://192.168.0.113/shequ/uchome/upload/2010-08/12814265524528.jpg"></a></li>
    <li class="ml5"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=20" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><b>三国群英传官方群</b></a>(今日:<span><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=20" rel="external nofollow" rel="external nofollow" rel="external nofollow" >0</a></span>)</li>
    <li class="ml5"></li>
    <li class="ml5">主题:<span>1</span>,贴数:<span>1</span></li>
   </ol>
          <ol class="mt10 ">
    <li class="quanzi_pic ml10"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=18" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img onerror="this.onerror=null;this.src='';" src="http://192.168.0.113/shequ/uchome/upload/2010-08/128142657314254.jpg"></a></li>
    <li class="ml5"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=18" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><b>飘渺仙剑客服群</b></a>(今日:<span><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=18" rel="external nofollow" rel="external nofollow" rel="external nofollow" >0</a></span>)</li>
    <li class="ml5"></li>
    <li class="ml5">主题:<span>0</span>,贴数:<span>0</span></li>
   </ol>
          <ol class="mt10 ml10">
    <li class="quanzi_pic ml10"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=17" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img onerror="this.onerror=null;this.src='';" src="http://192.168.0.113/shequ/uchome/upload/2010-08/128142658426959.jpg"></a></li>
    <li class="ml5"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=17" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><b>武林英雄客服群</b></a>(今日:<span><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=17" rel="external nofollow" rel="external nofollow" rel="external nofollow" >0</a></span>)</li>
    <li class="ml5"></li>
    <li class="ml5">主题:<span>1</span>,贴数:<span>1</span></li>
   </ol>
          <ol class="mt10 ">
    <li class="quanzi_pic ml10"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=25" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img onerror="this.onerror=null;this.src='';" src="http://192.168.0.113/shequ/uchome/upload/2010-08/12814265147740.jpg"></a></li>
    <li class="ml5"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=25" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><b>飘渺仙剑官方群</b></a>(今日:<span><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=25" rel="external nofollow" rel="external nofollow" rel="external nofollow" >0</a></span>)</li>
    <li class="ml5"></li>
    <li class="ml5">主题:<span>0</span>,贴数:<span>0</span></li>
   </ol>
          <ol class="mt10 ml10">
    <li class="quanzi_pic ml10"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=13" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img onerror="this.onerror=null;this.src='';" src="http://192.168.0.113/shequ/uchome/upload/2010-08/128142679512873.jpg"></a></li>
    <li class="ml5"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=13" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><b>游戏交友</b></a>(今日:<span><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=13" rel="external nofollow" rel="external nofollow" rel="external nofollow" >0</a></span>)</li>
    <li class="ml5">记录管理人员的意见或建议。</li>
    <li class="ml5">主题:<span>0</span>,贴数:<span>0</span></li>
   </ol>
          <ol class="mt10 ">
    <li class="quanzi_pic ml10"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=15" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img onerror="this.onerror=null;this.src='';" src="http://192.168.0.113/shequ/uchome/upload/2010-08/128142677312935.jpg"></a></li>
    <li class="ml5"><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=15" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><b>游戏交易</b></a>(今日:<span><a target="_blank" href="shequ/uchome/space.php?do=mtag&tagid=15" rel="external nofollow" rel="external nofollow" rel="external nofollow" >0</a></span>)</li>
    <li class="ml5">生活中的小窍门,都拿出来和大家分...</li>
    <li class="ml5">主题:<span>0</span>,贴数:<span>0</span></li>
   </ol>
         </div>
 </div>

效果图:

JS实现的tab切换选项卡效果示例

希望本文所述对大家JavaScript程序设计有所帮助。

Javascript 相关文章推荐
js中有关IE版本检测
Jan 04 Javascript
jQuery判断iframe中元素是否存在的方法
May 11 Javascript
JavaScript获取onclick、onchange等事件值的代码
Jul 22 Javascript
js获取IP地址的方法小结
Jul 01 Javascript
javascript倒计时效果实现
Nov 12 Javascript
JavaScript中setTimeout和setInterval函数的传参及调用
Mar 11 Javascript
微信小程序自定义导航隐藏和显示功能
Jun 13 Javascript
EasyUI的DataGrid绑定Json数据源的示例代码
Dec 16 Javascript
基于vue1和vue2获取dom元素的方法
Mar 17 Javascript
Vue实现点击当前元素以外的地方隐藏当前元素(实现思路)
Dec 04 Javascript
使用vue实现一个电子签名组件的示例代码
Jan 06 Javascript
vue使用video插件vue-video-player详解
Oct 23 Javascript
jQuery Pagination分页插件使用方法详解
Feb 28 #Javascript
完美解决input[type=number]无法显示非数字字符的问题
Feb 28 #Javascript
canvas红包照片实例分享
Feb 28 #Javascript
详解本地Node.js服务器作为api服务器的解决办法
Feb 28 #Javascript
jquery操作select取值赋值与设置选中实例
Feb 28 #Javascript
JS使用面向对象技术实现的tab选项卡效果示例
Feb 28 #Javascript
基于cookie实现zTree树刷新后展开状态不变
Feb 28 #Javascript
You might like
一个取得文件扩展名的函数
2006/10/09 PHP
用PHP实现弹出消息提示框的两种方法
2013/12/17 PHP
Laravel开启跨域请求的方法
2019/10/13 PHP
google地图的路线实现代码
2009/08/20 Javascript
javascript中的缓动效果实现程序
2012/12/29 Javascript
js和html5实现手机端刮刮卡抽奖效果完美兼容android/IOS
2013/11/18 Javascript
jQuery.event兼容各浏览器的event详细解析
2013/12/18 Javascript
用原生js做个简单的滑动效果的回到顶部
2014/10/15 Javascript
在其他地方你学不到的jQuery小贴士和技巧(欢迎收藏)
2016/01/20 Javascript
浅谈js中字符和数组一些基本算法题
2016/08/15 Javascript
使用ng-packagr打包Angular的方法示例
2018/09/21 Javascript
[04:29]DOTA2亚洲邀请赛小组赛第一日 TOP10精彩集锦
2015/02/01 DOTA
用yum安装MySQLdb模块的步骤方法
2016/12/15 Python
Python守护进程和脚本单例运行详解
2017/01/06 Python
Python中二维列表如何获取子区域元素的组成
2017/01/19 Python
python实现Flappy Bird源码
2018/12/24 Python
python实现两张图片拼接为一张图片并保存
2019/07/16 Python
PyQt5基本控件使用详解:单选按钮、复选框、下拉框
2019/08/05 Python
python 数据生成excel导出(xlwt,wlsxwrite)代码实例
2019/08/23 Python
Python中输入和输出(打印)数据实例方法
2019/10/13 Python
python正则过滤字母、中文、数字及特殊字符方法详解
2020/02/11 Python
python实现人机五子棋
2020/03/25 Python
python实现暗通道去雾算法的示例
2020/09/27 Python
eDreams巴西:廉价机票,酒店优惠和度假套餐
2017/04/14 全球购物
意大利制造的西装、衬衫和针对男士量身定制的服装:Lanieri
2018/04/08 全球购物
官方授权图形T恤和服装:Fifth Sun
2019/06/12 全球购物
AURALog面试题软件测试方面
2013/10/22 面试题
优秀党员转正的自我评价
2013/10/06 职场文书
机械设计及其自动化专业推荐信
2013/10/31 职场文书
网络教育自我鉴定
2013/11/01 职场文书
买房子个人收入证明
2014/01/16 职场文书
拆迁委托协议书
2014/09/15 职场文书
Python Django搭建文件下载服务器的实现
2021/05/10 Python
Python实现位图分割的效果
2021/11/20 Python
JavaWeb Servlet开发注册页面实例
2022/04/11 Java/Android
python双向链表实例详解
2022/05/25 Python