日期:2014-05-16 浏览次数:20322 次
//导航选项卡 /*更换显示样式*/ function setTab(m,n){ var tli = document.getElementById("menu"+m).getElementsByTagName("li"); var mli = document.getElementById("main"+m).getElementsByTagName("ul"); var faterLfet = document.getElementById("tabs1").offsetLeft; //得到父div到浏览器左边的距离 var titleWidth = tli[1].clientWidth; //得到一级菜单的宽度 var titleLeft = titleWidth * n; //得到第n个一级菜单到父div左边的距离 var left = faterLfet + titleLeft; //计算第n个一级菜单到浏览器左边的距离 var oneMenuMiddle = left - titleWidth / 2; //得到一级菜单重点与浏览器左边的距离 for(i=0;i<tli.length;i++){ tli[i].className=i==n?"hover":""; mli[i].style.display=i==n?"block":"none"; var tabs1Num = mli[n].clientWidth; //获取二级菜单的宽度 if(n == 0){ var twoLeft = oneMenuMiddle - tabs1Num / 2; //得到二级菜单与浏览器左边的距离 }else{ var twoLeft = oneMenuMiddle - tabs1Num / 2 -180; //得到二级菜单与浏览器左边的距离 } document.getElementById("fatherDiv").style.left = twoLeft; } }?