选项卡

"Hello World, Hello Blog"

Posted by wudimingwo on December 15, 2018

版本1.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var oBox = document.getElementsByClassName('box');
			var oButton = document.getElementsByTagName('button');
			var oBoxlen = oBox.length;
			for(var i = 0;i < oBoxlen;i++) {
			  (function (i) {
			    oButton[i].onclick = function (e) {
			      console.log('akgja');
			    	for(var j = 0; j < oBoxlen; j++) {
			    	 oBox[j].className = oBox[j].className.replace('active','');
			    	 oButton[j].className = oButton[j].className.replace('active','');
			    	}
			    	this.className += ' active';
			    	oBox[i].className += ' active';
			    }
			  })(i);
			}