span {
width: 100px;
text-align: center;
line-height: 30px;
border: 1px solid #ddd;
background-color: #eee;
display: inline-block;
}
.active {
border: 1px solid red;
color: red
}
var btns = document.querySelectorAll(‘span’);
console.log(btns);
// 绑定点击事件
for (var i = 0; i < btns.length; i++) {
btns[i].onclick = function () {
for (var j = 0; j < 3; j++) {
btns[j].setAttribute(‘class’, ‘’);
}
this.setAttribute(‘class’, ‘active’)
// for(var j = 0 ; j < 3 ; j++){
// div[j].setAttribute('class','');
// }
// this.setAttribute('class','show')
}
}