图像预加载问题 [英] Image preload problem

查看:81
本文介绍了图像预加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


请,有人可以告诉我为什么警报在下一页中显示为未定义

Hi,
Please, could someone tell me why the alert shows undefined in the following page

<html>
<head>
<title>test</title>
<script language="JavaScript">
var theLargeImg;
function loadImage(url)
{
theLargeImg = new Image();
theLargeImg.onload=imageLoaded();
theLargeImg.src = url;
}
function imageLoaded()
{
alert("img height="+theLargeImg.Height+";img width="+theLargeImg.Width+";complete = "+theLargeImg.complete+&"; src= "+theLargeImg.src);
}
</script>

</head>
<body>
<input type="button" onclick="javascript:loadImage('http://www.google.co.uk/intl/en_ALL/images/logos/images_logo_lg.gif')" value="Load Image">
</body>
</html>


谢谢,
理查德.


Thanks,
Richard.

推荐答案

1.您应该将事件onload放在"src"之后.
1. u should put event onload after the "src".
function loadImage(url)
      {
       theLargeImg = new Image();
       theLargeImg.src = url;
       theLargeImg.onload=imageLoaded();
      }


2."Height"和"Width",首字母均应为小写.


2. "Height" and "Width" ,both first letter should be low-case.


这篇关于图像预加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆