在學習js和dom編程藝術第六章有個問題卡住了,書上說插入外部js代碼的時候用addloadevent比較好。但是我的js代碼用window.onload就能觸發(fā),而用addLoadEvent就不行了。代碼如下: addLoadEvent(pic); function pic(){ var ul=document.getElementById("ul"); var li=ul.getElementsByTagName("a"); for(var i=0;i<li.length;i++){ li[i].onclick=function(){ showPic(this); return false; } } } function showPic(showp){ var showph = showp.getAttribute("href"); var placeholder = document.getElementById("placeholder"); placeholder.setAttribute("src",showph); var text = showp.getAttribute("title"); var showtext = document.getElementById("text"); showtext.firstChild.nodeValue=text; }我是放在head里面的,但是用window.onload就可以觸發(fā)啊,求大牛指點一二。
關于addloadEvent的問題
土豪碼農
2016-11-18 18:57:34