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>
這段JS代碼里為啥不能這樣寫
慕田峪8701529
2017-11-30 22:23:17