猿吟鹤唳本无意,不知下有行人行

选项卡-左右箭头

3<!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=utf-8" />
<title>左右点击选项卡</title>
<style type="text/css">
#box{width:300px; margin:0 auto;}
#box input{ padding:4px 10px; background:#ccc; display:inline-block;}
#box input.on{ background:red;}
#box span{color:red; cursor:pointer;}
#box div{ width:298px; border:1px solid #000; display:none; height:200px;}
</style>
<script>
window.onload=function(){
	var oBox=document.getElementById('box');
	var oBtn=oBox.getElementsByTagName('input');
	var oCon=oBox.getElementsByTagName('div');
	var oPrev=document.getElementById('prev');
	var oNext=document.getElementById('next');
	var iNow=0;

	for(var i=0;i<oBtn.length;i++){
		oBtn[i].index=i;
		oBtn[i].onmouseover=function(){
			iNow=this.index;
			tb();
		}	
	}
	oPrev.onclick=function(){
		iNow--;
		if(iNow==-1){
			iNow=2;
		}
		tb();
	}
	oNext.onclick=function(){
		iNow++;
		if(iNow==3){
			iNow=0;
		}
		tb();
	}
	function tb(){
		for(var i=0;i<oBtn.length;i++){
			oBtn[i].className='';
			oCon[i].style.display='none';
		}
		oBtn[iNow].className='on';
		oCon[iNow].style.display='block';
	}

}

</script>
</head>

<body>
<div id="box">
<input type="button" value="菜单一" /><input type="button" value="菜单二" /><input type="button" value="菜单三" />
<span id="prev">←</span>  <span id="next">→</span>
<div style="display:block">12121212</div>
<div>22222222222</div>
<div>33333333333</div>
</div>
</body>
</html>

 Demo

发表评论

您的电子邮箱地址不会被公开。