div+css+js模拟tab切换效果 事件绑定 IE,firefox兼容
作者:bea
div+css+js模拟tab, 我这个版本,理论上可以添加无限个tab,而且,你只要管内容的添加行了,不需要改JS 当然,你得会DIV才行. <!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/
div+css+js模拟tab, 我这个版本,理论上可以添加无限个tab,而且,你只要管内容的添加行了,不需要改JS
当然,你得会DIV才行.
<!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>div+css+js模拟tab</title>
<style><!--
body{margin:0;padding:0; text-align:center; background-color:#CCCCCC}
a{text-decoration:none}
#header ul{padding:0;margin:0}
#header ul li{list-style:none; float:left}
#header ul li span{display:inline-block; border:1px solid #000; cursor:hand;}
#ccc{ clear:both; background-color:#009933; text-align:left}
#ccc div.cont{display:none}
--></style>
</head>
<body>
<div id="wrap">
<div id="header">
<ul>
<li><a href="#"><span>框1111</span></a></li>
<li><a href="#"><span>框2222</span></a></li>
<li><a href="#"><span>框3333</span></a></li>
<li><a href="#"><span>框4444</span></a></li>
</ul>
</div>
<div id="ccc">
<div class="cont">
这里是内容撒.111..<br>
这里是内容撒.111..<br>
这里是内容撒.111..<br>
</div>
<div class="cont">
这里是内容撒222..<br>
这里是内容撒.222..<br>
这里是内容撒.222..<br>
</div>
<div class="cont">
这里是内容撒.333..<br>
这里是内容撒.333..<br>
这里是内容撒.333..<br>
</div>
<div class="cont">
这里是内容撒.444..<br>
这里是内容撒.444..<br>
这里是内容撒.444..<br>
</div>
</div>
</div>
<script type="text/javascript"><!--
function $(o){return document.getElementById(o)}
var ospan=$('header').getElementsByTagName('span');
var odiv=$('ccc').getElementsByTagName('div');
for(var i=0;i<ospan.length;i++){
ospan[i].alt=i;
ospan[i].onclick=function(){
var nid=parseInt(this.alt);hidAll();
this.style.backgroundColor='#fff';
odiv[nid].style.display='block';
}
}
function hidAll(){
for(var i=0;i<odiv.length;i++){
odiv[i].style.display='none';
ospan[i].style.backgroundColor='';
}
}
// --></script>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
有用 | 无用
当然,你得会DIV才行.
<!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>div+css+js模拟tab</title>
<style><!--
body{margin:0;padding:0; text-align:center; background-color:#CCCCCC}
a{text-decoration:none}
#header ul{padding:0;margin:0}
#header ul li{list-style:none; float:left}
#header ul li span{display:inline-block; border:1px solid #000; cursor:hand;}
#ccc{ clear:both; background-color:#009933; text-align:left}
#ccc div.cont{display:none}
--></style>
</head>
<body>
<div id="wrap">
<div id="header">
<ul>
<li><a href="#"><span>框1111</span></a></li>
<li><a href="#"><span>框2222</span></a></li>
<li><a href="#"><span>框3333</span></a></li>
<li><a href="#"><span>框4444</span></a></li>
</ul>
</div>
<div id="ccc">
<div class="cont">
这里是内容撒.111..<br>
这里是内容撒.111..<br>
这里是内容撒.111..<br>
</div>
<div class="cont">
这里是内容撒222..<br>
这里是内容撒.222..<br>
这里是内容撒.222..<br>
</div>
<div class="cont">
这里是内容撒.333..<br>
这里是内容撒.333..<br>
这里是内容撒.333..<br>
</div>
<div class="cont">
这里是内容撒.444..<br>
这里是内容撒.444..<br>
这里是内容撒.444..<br>
</div>
</div>
</div>
<script type="text/javascript"><!--
function $(o){return document.getElementById(o)}
var ospan=$('header').getElementsByTagName('span');
var odiv=$('ccc').getElementsByTagName('div');
for(var i=0;i<ospan.length;i++){
ospan[i].alt=i;
ospan[i].onclick=function(){
var nid=parseInt(this.alt);hidAll();
this.style.backgroundColor='#fff';
odiv[nid].style.display='block';
}
}
function hidAll(){
for(var i=0;i<odiv.length;i++){
odiv[i].style.display='none';
ospan[i].style.backgroundColor='';
}
}
// --></script>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- javascript 年月日联动实现核心代码
- 兼容firefox的文本框只能输入两位小数的数字的代码
- js Firefox 加入收藏夹功能代码 兼容Firefox 和 IE
- Javascript和Ajax中文乱码吐血版解决方案
- 利用jQuery的$.event.fix函数统一浏览器event事件处理
- jQuery 连续列表实现代码
- jQuery解决iframe高度自适应代码
- IE 上下滚动展示模仿Marquee机制
- Js获取table当前tr行的值的代码
- javascript 翻页测试页(动态创建标签并自动翻页)
- js控制div及网页相关属性的代码
- jQuery 淡入淡出、展开收缩菜单实现代码
- JQuery Tips(4) 一些关于提高JQuery性能的Tips
- JS 在数组插入字符的实现代码(可参考JavaScript splice() 方法)
- JS 的应用开发初探(mootools)
- 用js实现层随着内容大小动态渐变改变 推荐
- javascript demo 基本技巧
- javascript option onclick事件ie解决方案 兼容ie,firefox
- IE和Firefox下event事件杂谈