function Tab(oParent,child) {
this.oParent= document.getElementById(oParent);
this.aInput = this.oParent.getElementsByTagName(child);
this.aDiv = this.oParent.getElementsByTagName('div');
}
Tab.prototype.init=function () {
for (var i = 0 ; i<this.aInput.length;i++){
var that = this;
this.aInput[i].index=i;
this.aInput[i].onclick=function () { //为什么这里不能直接写成this.aInput[i].onclick=that.change(this)
that.change(this);
}
}
Tab.prototype.change=function (obj) {
for(var j=0 ;j<this.aInput.length;j++){
this.aInput[j].className ='';
this.aDiv[j].style.display='none';
}
obj.className = 'active'
this.aDiv[obj.index].style.display='block';
}
}
window.onload=function () {
var tabSwitch = new Tab('div1','input');
tabSwitch.init('div1')
}
</script>
添加回答
举报
0/150
提交
取消