在学习js和dom编程艺术第六章有个问题卡住了,书上说插入外部js代码的时候用addloadevent比较好。但是我的js代码用window.onload就能触发,而用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就可以触发啊,求大牛指点一二。
HiFrontend
相关分类