<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#div1 button{width: 100px;height: 30px;background-color: gray;color: white;font-size: 18px}
#div1 .active{background-color: orange;color: blue}
#div1 div{width: 340px;height: 300px;border: 1px solid black;display: none}
</style>
<script>
window.onload = function(){
var oDiv1 = document.getElementById("div1");
var aBtns = oDiv1.getElementsByTagName("button");
var aDivs = oDiv1.getElementsByTagName("div");
//给每一个按钮添加点击
for(var i = 0; i < aBtns.length; i++){
aBtns[i].index = i;
aBtns[i].onclick = function(){
//取消所有按钮的样式
for(var j = 0; j < aBtns.length; j++){
aBtns[j].className = '';
aDivs[j].style.display = 'none';
}
aDivs[this.index].style.display = 'block';
this.className = 'active';
}
}
}
</script>
</head>
<body>
<div id = 'div1'>
<button class = "active">HTML5</button>
<button>Python</button>
<button>Java</button>
<div style='display: block;'>HTML5是web中核心语言HTML的规范</div>
<div>Python是一种面向对象的动态类型语言</div>
<div>Java是一门面向对象编程语言</div>
</div>
</body>
</html>