您几乎可以依赖为 Image节点 触发的本机
onload和
onerror事件处理程序。所以看起来像 __
var images = ['users/john/images/image01.jpg','users/mike/img/image01.jpg','some/more/path/image01.jpg'];(function _load( img ) { var loadImage = new Image(); loadImage.onerror = function() { // image could not get loaded, try next one in list _load( images.shift() ); }; loadImage.onload = function() { // this image was loaded successfully, do something with it }; loadImage.src = img;}( images.shift() ));此代码可能比您实际要求的要多。您基本上可以在阵列中添加任意数量的 图像路径 ,但脚本将搜索列表,直到成功加载一张图像为止。



