效果: 代码: 复制代码 代码如下: <BR> #red<BR> {<BR> width: 260px;<BR> height: 200px;<BR> background: #FF0000;<BR> display: none;<BR> }<BR> #green<BR> {<BR> width: 260px;<BR> height: 200px;<BR> background: #00FF00;<BR> display: none;<BR> }<BR> #yellow<BR> {<BR> width: 260px;<BR> height: 200px;<BR> background: #FFFF00;<BR> display: none;<BR> }<BR> #blue<BR> {<BR> width: 260px;<BR> height: 200px;<BR> background: #0000FF;<BR> display: none;<BR> }<BR> <BR> window.onload = function () {<BR> var btn = document.getElementsByTagName('input');<BR> var div = document.getElementsByTagName('div');<BR> for (var i = 0; i < btn.length; i++) {<BR> btn[i].index = i;<BR> btn[i].onclick = function () {<BR> for (var i = 0; i < btn.length; i++) {<BR> btn[i].style.background = '';<BR> }<BR> switch (this.value) {<BR> case '红色': this.style.background = '#FF0000';<BR> break;<BR> case '绿色': this.style.background = '#00FF00';<BR> break;<BR> case '黄色': this.style.background = '#FFFF00';<BR> break;<BR> case '蓝色': this.style.background = '#0000FF';<BR> break;<BR> }<BR> for (var i = 0; i < btn.length; i++) {<BR> div[i].style.display = '';<BR> }<BR> div[this.index].style.display = 'block';<BR> }<BR> }<BR> };<BR>