PHP中文网2017-06-26 10:54:10
GlobalEventHandlers.onload
貌似window.onload在同一个html引入的js文件里只能写一次。
你这样写试试:(我只是简略的写了代码,没测试,自己测测改改吧)
window.onload = function(){
//父选项卡控制
tab("tab_t","li","tab_c","a_b","act","p","onclick");
//子选项卡控制
tab("bab_t","li","bab_c","b_b","bct","p","onclick");
};
function tab(tab_t,tab_t_tag,tab_c,tab_c_li,tab_t_li,tag_c_tag,evt){
var tab_t = document.getElementById(tab_t);
var tab_t_li = tab_t.getElementsByTagName(tab_t_tag);
var tab_c = document.getElementById(tab_c);
var tab_c_li = document.getElementsByClassName(tab_c_li);
var len = tab_t_li.length;
var i=0;
for(i=0; i<len; i++){
tab_t_li[i].index = i;
tab_t_li[i][evt] = function(){
for(i=0; i<len; i++){
tab_t_li[i].className = '';
tab_c_li[i].className = 'hide '+tab_c_li+'';
}
tab_t_li[this.index].className = ''+tab_t_li+'';
tab_c_li[this.index].className = ''+tab_c_li+'';
}
}
}