<!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>
.active{background:#3CC;}
.div2{width:300px;height:200px; border:1px #666666 solid;display:none;}
</style>
<script>
window.onload=function(){
var odiv=document.getElementById('div1');
var btn=odiv.getElementsByTagName('input');
var div2=odiv.getElementsByTagName('div') ;
for(i=0;i<btn.length;i++)
{
btn[i].index=i;
btn[i].onclick=function()//按钮的第i个点击事件
{
for(i=0;i<btn.length;i++)
{
btn[i].className='';
div2[i].style.display='none';
}
this.className='active';
div2[this.index].style.display='block';
};
}
};
</script>
</head>
<body>
<div id="div1">
<input type="button" class="active" value="1"/>
<input type="button" value="2"/>
<input type="button" value="3"/>
<input type="button" value="4"/>
<div class="div2" style="display:block;">11</div>
<div class="div2">22</div>
<div class="div2">33</div>
<div class="div2">44</div>
</div>
</body>
</html>