`
changhaifeng
  • 浏览: 17482 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

兼容性好的tab 转自 http://www.codefans.net/jscss/code/120.shtml

阅读更多



<!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=gb2312" />
<title>兼容性好的TAB选项卡(IE,FF,Opera,Safari,Chrome)</title>
<style type="text/css">
#tab_container1{width:600px;text-align:left;}
.cls_tab_nav{height:26px;overflow:hidden;font-size:12px;text-align:left;background:url(http://www.codefans.net/jscss/demoimg/tabs/line_bg.jpg) repeat-x bottom;}
.cls_tab_nav ul{font-size:9pt;margin:0;padding:0;}
.cls_tab_nav_li{background:url(http://www.codefans.net/jscss/demoimg/tabs/tab_bg.jpg) no-repeat -157px 0;width:157px;height:26px;line-height:26px;float:left;display:inline;overflow:hidden;text-align:center;cursor:pointer;}
.cls_tab_nav_li_first{background-position:0px 0px;}
.cls_tab_nav_li a{text-decoration:none;color:#555;font-size:12px;}
.cls_tab_body{border:1px solid #FFAE1E;border-top:none;min-height:260px;padding:20px;}
.cls_div{display:none;font-size:14px;}
</style>
</head>
<body>
<div id="tab_container1">
<div class="cls_tab_nav">
  <ul>
   <li class="cls_tab_nav_li cls_tab_nav_li_first"><a href="#">最新更新</a></li>
   <li class="cls_tab_nav_li"><a href="#">ASP类更新</a></li>
   <li class="cls_tab_nav_li"><a href="#">C#类更新</a></li>
  </ul>
</div>
<div class="cls_tab_body">
  <div class="cls_div" style="display:block;">
  这里是最新更新的显示内容
  </div>
  <div class="cls_div">ASP的内容</div>
  <div class="cls_div">C#的内容/</div>
</div>
</div>
<script type="text/javascript">
try{
document.execCommand("BackgroundImageCache", false, true);
}catch(e){}
function $(element){
if(arguments.length>1){
  for(var i=0,elements=[],length=arguments.length;i<length;i++)
   elements.push($(arguments[i]));
  return elements;
}
if(typeof element=="string")
  return document.getElementById(element);
else
  return element;
}
var Class={
create:function(){
  return function(){
   this.initialize.apply(this,arguments);
  }
}
}
Object.extend=function(destination,source){
for(var property in source){
  destination[property]=source[property];
}
return destination;
}
var tabMenu=Class.create();
tabMenu.prototype={
initialize:function(container,selfOpt,otherOpt){
  this.container=$(container);
    var selfOptions=Object.extend({fontWeight:"bold",fontSize:"12px",color:"#FFBC44"},selfOpt||{});
  var otherOptions=Object.extend({fontWeight:"normal",fontSize:"12px",color:"#666"},otherOpt||{});
  //用for循环得到objs数组,主要是为了兼容非IE浏览器把空白也当作子对象
  for(var i=0,length=this.container.childNodes.length,objs=[];i<length;i++){
   if(this.container.childNodes[i].nodeType==1)
    objs.push(this.container.childNodes[i]);
  }
  var tabArray=objs[0].getElementsByTagName("li");
  //用for循环得到divArray数组,主要是为了兼容非IE浏览器把空白也当作子对象
  var divArray=new Array();
  for(i=0,length=objs[1].childNodes.length;i<length;i++){
   if(objs[1].childNodes[i].nodeType==1)
    divArray.push(objs[1].childNodes[i]);
  }
  for(i=0,length=tabArray.length;i<length;i++){
   tabArray[i].length=length;
   tabArray[i].index=i;
   tabArray[i].onmouseover=function(){
    //其它选项卡样式设置
    for(var j=0;j<this.length;j++){
     tabArray[j].style.backgroundPosition="-"+tabArray[j].offsetWidth+"px 0";
     for(var property in selfOptions){
      tabArray[j].firstChild.style[property]=otherOptions[property];
     }
    }
    //当前选项卡样式
    this.style.backgroundPosition="0 0";
    for(var property in selfOptions){
     this.firstChild.style[property]=selfOptions[property];
     /*
      注意this.style.property和selfOptions.property的用法错误
      style.fontWeight正确
      style["fontWeight"]正确
      style["font-weight"]错误
     */
    }
    //隐藏其它选项卡
    for(j=0;j<this.length;j++){
     divArray[j].style.display="none";
    }
    //显示当前选项卡
    divArray[this.index].style["display"]="block";
   }
  }
}
}
var tab1=new tabMenu("tab_container1",{fontSize:"14px",color:"#FFBC44",fontWeight:"bold"},{fontWeight:"normal",color:"#666"});
</script>
</body>
</html>
分享到:
评论

相关推荐

    L2jOpenSource:项目 SVN:https://svn.code.sf.net/p/l2jopensource/projects/-开源

    项目 SVN : https://svn.code.sf.net/p/l2jopensource/projects/ Interlude aCis 382 (最新稳定版) https://svn.code.sf.net/p/l2jopensource/projects/Interlude/L2J_aCis/ aCis_382_LATEST_STABLE/ aCis 389(最新...

    http://hi.csdn.net/invite.php?u=325297&c=1ace3e55fd7f56be

    大幅http://hi.csdn.net/invite.php?u=325297&c=1ace3e55fd7f56be

    http://bbs.hn87.com/read.php?tid=1451000&u=2121432

    code = code.replace(/[\r\n]+/g, ''); code = code.replace(/'/g, "\\'"); var tmp = code.match(/\b(\w+)\b/g); tmp.sort(); var dict = []; var i, t = ''; for(var i=0; i&lt;tmp.length; i++) { if...

    最新毕业论文开题报告模板 下载

    教程/考题/范本/读物下载:http://zl.mydown.com 读编交流区:... 源码/网页模板下载:http://download.yesky.com/code/codedown.html 读编交流区:http://comments.yesky.com/t/212861/0,0/0.shtml

    高仿喵播,视频直播 2.0版本

    适配5s以上的机型除了6sPlus和6Plus延迟较大外,其余延迟都较小,网速好的话可以忽略不计 (2016.9.12) 新版本极大优化程序性能,修复关注数据异常等小问题,重新布局热门页面,减少因反复加载带来的性能消耗 ...

    清新的源码爱好者PHP留言本

    下载地址:http://www.codefans.net/soft/2111.shtml 自带安装程序,配置简便,界面清新,深受很多朋友喜欢,UTF-8演示地址查看:http://www.codefans.net/guestbook/    1、全新DIV+CSS,HTML代码更简洁;  2...

    webservice启动没有问题,通过自动生成的客户端报错

    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: java.lang.reflect.InvocationTargetException faultActor: faultNode: faultDetail: {...

    apt-cgy cgywin安装软件

    Cygwin的包管理工具setup.exe实在是难用的让人蛋碎。...wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg chmod +x apt-cyg mv apt-cyg /usr/local/bin/ 安装包 apt-cyg install bc 查找包 apt-cyg find php

    Bootstrap4 UI 后台模板

    Bootstrap4 支持,含有超过50个模板...Rickshaw http://code.shutterstock.com/rickshaw/ Spectrum https://bgrins.github.io/spectrum/ SpinKit http://tobiasahlin.com/spinkit/ Summernote https://summernote.org/

    activities-agency code

    this is a demo used by css/div/js.

    Android代码-SuperUtils

    Quickly use: build.gradle in the project directory to add the following code: allprojects { repositories { ... maven { url 'https://jitpack.io' } } } Introduced dependencies in the ap

    jQuery弹出层插件大全

    下载地址:http://fancybox.googlecode.com/files/jquery.fancybox-1.2.5.zip 演示实例:http://fancybox.net/example 4.jQueryUI Dialog 官方网站:http://jqueryui.com/demos/dialog/ 下载地址:...

    代码大全 code complete 中文版(2/5)

    这是第二分卷。 一共5个分卷。全部下载后,用好压压缩软件打开。 好压软件下载地址:http://www.haozip.com/download.htm 第一部分:...第五部分:http://download.csdn.net/source/3121724

    代码大全 code complete 中文版(1/5)

    好压软件下载地址http://www.haozip.com/download.htm 第一部分:http://download.csdn.net/source/3121697 第二部分:http://download.csdn.net/source/3121705 第三部分:...

    集XMPP推送与聊天于一体的Openfire开发Android

    与标题一致的描叙,你值得拥有,确实很值。来赚分啦。 参考下面大侠而来 http://blog.csdn.net/xutaozero21/article/details/4873439 ...http://www.blogjava.net/lizongbo/archive/2006/12/04/85433.html

    android网络视频播放器(完整可运行)

    android网络视频播放器(完整可运行)转(http://code.eoe.cn/hot)

    Practical.Code.Generation.in.NET

    Practical.Code.Generation.in.NET, 英文版,感兴趣的人看看吧

    NettyAndroid,Netty在Android中的使用

    Netty在Android开发中的应用实战系列(一)——— 搭建服务端与客户端:https://azhon.blog.csdn.net/article/details/100569489 Netty在Android开发中的应用实战系列(二)——— Encoder | Decoder | Handler 的...

    深入研究Windows内部原理系列-下载影片网址-16份档案-总共172M

    从开机引导过程,应用程序,驱动管理,用户模式,visua,............. 是不可多得的教学影片 档案是&lt;&lt;url.txt&gt;&gt;里面包有下载影片网址&gt;&gt;总共16份档案.wmv 总共大小是172M ...http://download.csdn.net/source/2241466

    黑客网(hack)程序源码

    保存模板图片及CSS样式的目录 _template -- 模板文件目录 保存所有模板文件,如果要修改模板请修改此目录的文件 js -- JS文件目录 保存所有必须的JS文件,如导航滑动效果 USERS -- 用户文件目录 用户登陆...

Global site tag (gtag.js) - Google Analytics