<分区>
Possible Duplicate:
Check if an image is loaded (no errors) in JavaScript
通过设置 img.src 由 javascript 加载后。
谢谢...!
标签 javascript
<分区>
Possible Duplicate:
Check if an image is loaded (no errors) in JavaScript
通过设置 img.src 由 javascript 加载后。
谢谢...!
最佳答案
您可以像这样使用 load
事件:
var img = document.getElementById('imgID');
// or
var img = new Image;
img.onload = function(){
alert('The image has been loaded');
img.src = 'image path here';
};
或者当你使用 window
的 load
事件时,图像会在那时加载:
window.onload = function(){
// everything is loaded now
};
关于javascript - 如何检查图像是否已成功预加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4364332/
相关文章:
javascript - Polymer 和 Three.js
javascript - 如果在免费的 jqgrid 列中单击,如何执行 ajax 调用并重定向到其他页面
javascript - 如何创建一个特定的X*X尺寸表? (战舰游戏)(HTML、CSS、JS)
javascript - 根据值 crm 2011 更改字段的颜色
javascript - 使用 Facebook Graph API 创建带有位置的帖子
javascript - 来自远程 API 的 Set-Cookie 不起作用