function changefn(i){ for(j=0;j<linode.length;j++){ if(j===i){ linode[j].className ="active" ; tagnode[(j+1)].className = "show" ; } else{ linode[j].className = "" ; tagnode[(j+1)].className = "hide"; } } } window.onload = function() { var linodes = document.getElementById("ul1"); var linode = linodes.childNodes; var tagnode = document.getElementById("tab-list").childNodes; for(i=0;i<linode.length;i++){ linode[i].setAttribute("onmouseover",changefn(i)); }// JS实现选项卡切换 }
1 回答
stone310
TA贡献361条经验 获得超191个赞
最后一句 linode[i].setAttribute("onmouseover",changefn(i)); 要写成字符串形式
linode[i].setAttribute("onmouseover","changefn(i)"),如果没引号,相当于函数执行,那就还没等事件触发,函数就自动执行了
添加回答
举报
0/150
提交
取消