為什么不能用這個?http://idcbgp.cn/video/3233
????function?getclsname(clsname,parent){ ???? var?oparent=parent?document.getElementById(parent):document, ???? eles=[], ???? elements=oparent.getElementsByTagName('*'); ???? for(var?i=0;i<elements.length;i++){ ???? if(elements[i].className==clsname){ ???? eles.push(elements[i]); ???? } ???? } ???? return?eles; ????} ????function?getstyle(ele,sty){ ???? if(ele.currentStyle){ ???? return?ele.currentStyle[sty]; ???? }else{ ???? return?window.getComputedStyle(ele,null)[sty]; ???? } ????} ???? ???? ????????window.onload?=?function?()?{ ???????? var?lis=document.getElementsByTagName('li'); ???????? //console.log(getclsname('toptitle',null)[0]); ???????? var?div_1=getclsname('toptitle',null)[0];//document.getElementsByTagName('ul')[0].getElementsByTagName('div')[0], ???????? wd=parseInt(getstyle(div_1,'height')); ???????? for(var?i=0;i<lis.length;i++){ ???????? lis[i].onmouseover=function(){ ???????? this.getElementsByTagName('div')[0].style.display='block'; ???????? this.getElementsByTagName('span')[0].className='my_span'; ???????? var?a=this.getElementsByTagName('div')[0].offsetHeight; ???????? //var?a=this.getclsname('submenu',null)[0]; ???????? console.log(a); ???????? } ???????? lis[i].onmouseleave=function(){ ???????? this.getElementsByTagName('div')[0].style.display='none'; ???????? this.getElementsByTagName('span')[0].className=''; ???????? } ???????? var?h=i*parseInt(getstyle(lis[i],'height'))+wd; ???????? } ????????}
這一段的,this.getclsname('submenu',null)[0];,
這句會報錯:Uncaught TypeError: this.getclsname is not a function,
如果換成了,this.getELementsByTagName('div')[0]就沒有問題呢?
非常感謝!
2016-07-08
var _this=this;
getclsname('submenu',_this)[0] ?這樣可以么 ?我也沒試過啊 ?那個有onmouseleave事件嗎 ?