function picFun(){
try{
var imgObjs=document.images;
for (var i=0; imgObjs.length ; i++){
var curObj=imgObjs[i];
if (curObj.complete==false){
reloadPic(curObj);
}
//else{
// if (curObj.onclick==null ) {
// curObj.onclick=openPic;
// }
//}
}
}catch (e){}
}
function reloadPic(imgObj){
var imgIndex=Math.round(Math.random()*5);
imgObj.src=" http://img.mop.com/images/error/X00"+imgIndex+".gif";
}
function openPic(){
window.open(this.src, "","");
}
try{
var imgObjs=document.images;
for (var i=0; imgObjs.length ; i++){
var curObj=imgObjs[i];
if (curObj.complete==false){
reloadPic(curObj);
}
//else{
// if (curObj.onclick==null ) {
// curObj.onclick=openPic;
// }
//}
}
}catch (e){}
}
function reloadPic(imgObj){
var imgIndex=Math.round(Math.random()*5);
imgObj.src=" http://img.mop.com/images/error/X00"+imgIndex+".gif";
}
function openPic(){
window.open(this.src, "","");
}
本文介绍了一种处理网页中图片加载失败的方法,通过自定义函数实现图片源的替换及点击预览功能。该方案利用JavaScript检测图片加载状态,若加载失败则更换为备用图片,并为每张图片添加点击事件以便于在新窗口中打开。
578

被折叠的 条评论
为什么被折叠?



