window.onload方法被覆蓋了,把兩塊程式碼放一塊,或是用addEventListener
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+''; } } }
window.onload方法被覆蓋了,把兩塊程式碼放一塊,或是用addEventListener
GlobalEventHandlers.onload
貌似window.onload在同一個html引進的js檔案裡只能寫一次。
你這樣寫試試:(我只是簡略的寫了程式碼,沒測試,自己測改吧)