哪里有问题?http://www.imooc.com/video/901
function getclsname(cls,parent){ var oparent=parent?document.getElementById(parent):document; var eles=[]; var elements=oparent.getElementsByTagName("*"); for(var i=0;i<elements.length;i++){ if(elements[i].className==cls){ eles.push(elements[i]); } } return eles; } window.onload=function(){ window.onscroll=function(){ var top=document.documentElement?document.documentElement.scrollTop:document.body.scrollTop; var menus=document.getElementById("menu").getElementsByTagName("a"); var items=getclsname("item"); var currentid=""; for(var i=0;i<items.length;i++){ var it=items[i]; var itemstop=it.scrollTop; if(top>itemstop-200){ currentid=it.id; }else{ break; } } if(currentid){ for(var j=0;j<menus.length;j++){ var mu=menus[j]; var href=mu.href.split("#"); if(href[href.length-1]!=currentid){ mu.className=""; }else{ mu.className="current"; } } } } }
非常感谢!