<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.on {
background-color: blue;
}
div {
width: 100px;
height: 100px;
border: 1px solid palegoldenrod;
display: none;
}
</style>
<script>
window.onload = function() {
var oDiv = document.getElementsByTagName('div');
var aBtn = document.getElementsByTagName('input');
for (var i = 0; i < aBtn.length; i++) {
aBtn[i].abc = i;
aBtn[i].onclick = function() {
for (var i = 0; i < aBtn.length; i++) {
aBtn[i].className = '';
oDiv[i].style.display = 'none'
}
this.className = 'on';
/* alert(this.value); */
oDiv[this.abc].style.display = 'block';
}
}
}
</script>
<body>
<input type="button" value="aaa">
<input type="button" value="bbb">
<input type="button" value="ccc">
<div>aaa</div>
<div>bbb</div>
<div>ccc</div>
<script>
</script>
</body>
</html>
運行結果