写了一个函数,在页面中引用,加载图片的时候调用这个函数。函数生效了,但是在控制台有显示报错。把那个函数单独拿出来做个demo的时候,也不报错,但是和其他的js代码放在一起就一直报错,不知道什么原因。希望有懂的大神们指点一下。Uncaught ReferenceError: AutoResizeImage is not defined代码如下js//图片等比缩放function AutoResizeImage(maxWidth, maxHeight, objImg) { var img = new Image(); img.src = objImg.src; var hRatio; var wRatio; var Ratio = 1; var w = img.width; var h = img.height; wRatio = maxWidth / w; hRatio = maxHeight / h; if (maxWidth == 0 && maxHeight == 0) { Ratio = 1; } else if (maxWidth == 0) {// if (hRatio < 1) Ratio = hRatio; } else if (maxHeight == 0) { if (wRatio < 1) Ratio = wRatio; } else if (wRatio < 1 || hRatio < 1) { Ratio = (wRatio <= hRatio ? wRatio : hRatio); } if (Ratio < 1) { w = w * Ratio; h = h * Ratio; } objImg.height = h; objImg.width = w;}html<center><img onerror="this.src='/Content/images/nopic.jpg'" data-src="@BuildEffectImage(effectImage, 0, 625)" src="@ConfigHelper.CdnPrefix/Content/images/NewHome/white.png" class="coverimage" height="625" onload="AutoResizeImage(830, 0, this);" /></center>报错图片
添加回答
举报
0/150
提交
取消