<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>选项卡</title>
<style type="text/css">
#div1 .active{ background: yellow;}
#div1 div{ width: 200px; height: 200px;background: #ccc; border: 1px solid #999; display: none; }
</style>
<script>
window.onload=function {
var oDiv=document.getElementById('div1');
var aBtn=oDiv.getElementsByTagName('input');
var aDiv=oDiv.getElementsByTagName('div');
for(var i=0; i< aBtn.length;i++)
{
aBtn[i].index=i;
aBtn[i].onclick=function()
{
for(var i=0;i<aBtn.length;i++)
{
aBtn[i].className='';
aDiv[i].style.display='none';}
this.className='active';
aDiv[this.index].style.display='block';
};
}
}
</script>
</head>
<body>
<div id="div1">
<input type="button" name="" value="段落1">
<input type="button" name="" value="段落2">
<input type="button" name="" value="段落3">
<input type="button" name="" value="段落4">
<div style="display:block;">第一段文字</div>
<div>第二段文字</div>
<div>第三段文字</div>
<div>第四段文字</div>
</div>
</body>
</html>
千秋此意
qq_心做_0
相关分类