<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div{display:none;}
.show{display:block;}
.active{background-color:yellow;}
</style>
</head>
<body>
<input type="button" value="tab1">
<input type="button" value="tab2">
<input type="button" value="tab3">
<div>div1</div>
<div>div2</div>
<div>div3</div>
<script>
var tabs = document.getElementsByTagName('input');
var divs = document.getElementsByTagName('div');
for(var i=0;i<tabs.length;i++){
tabs[i].onclick = function(){
for(var j=0;j<tabs.length;j++){
divs[j].className = '';
tabs[j].className = '';
}
this.className = 'active';
divs[i].className = 'show';
}
}
</script>
</body>
</html>为什么会出错呢。。for(var i=0;i<tabs.length;i++){为什么这里改成let就可以??
添加回答
举报
0/150
提交
取消