大家好,我正在制作一个网站(http://euroscala.balkanium.com/),它有一个菜单,当你点击一个菜单项时,应该会出现一个缩略图列表。我正试图预载所有应该出现的图像,然后显示它们。它适用于除IE以外的所有浏览器(我有版本8)。我已经把代码的人愿意到这里看看:http://jsfiddle.net/THpgM/2/Javascript为什么不执行此代码?
我认为问题就出在这一段代码(这是附近的第一功能的小提琴底部)
img.onload = (function(i){
// code here is executed
return function(){
// code here is not
++totalLoaded;
document.getElementById("li" + i).style.height = this.height + "px";
document.getElementById("li" + i).setAttribute("data-height", this.height);
if(totalLoaded == totalThumbs){
// do some stuff
}
};
})(i);
我花了2天试图弄清楚这一点。如果有人可以请帮助我,这将不胜感激。
尝试使用带有“data-height”的下标符号...例如'someElement [“data-height”] = 1'或'var height = someElement [“data-height”]'而不是getAttribute/setAttribute。 –
那到底出了什么问题? –
@MarkLinus当我在评论中写道,'return ...'后面的代码不会执行 –