weibo_E才是Eliza_J_0
2015-05-01 19:43
function bind(el,eventType, callback){ if(typeof el.addEventListener === "function"){ el.addEventListener(eventType, callback,false); }else if(typeof el.attachEvent === "function"){ el.attechEvent("on" + eventType,callback); } } function mouseoverHandler(e){ var target = e.target || e.srcElement; var outer = document.getElementById("subject"); var list = outer.getElementsByTagName("li"); for(var i = 0; i < list.length; i++){ list[i].className = ""; } while(target.tagName != "LI" && target.tagName != "BODY"){ target = target.parentNode; } target.className = "big"; } function initList(){ var outer = document.getElementById("subject"); var list = outer.getElementsByTagName("li"); for(var i=0; i < list.length; i++){ bind(list[i],"mouseover", mouseoverHandler); } } initList();
要把<script type="text/javascript" src="demo.js"></script>放在body里面
为啥我用你的还是不行……
我知道了,我的<script type="text/javascript" src="demo.js"></script>这句放在上面了。。。
你确定是对的吗,怎么还是会出现你提出过的问题,就是ncaught TypeError: Cannot read property 'getElementsByTagName' of null
很赞,不过有点小粗心哈。
else if(typeof el.attechEvent === "function"){
el.attechEvent("on" + eventType,callback);
}
这里的attechment应该是attachEvent
手风琴效果
40811 学习 · 111 问题
相似问题