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需刷新才能执行]





有用  |  无用

猜你喜欢