站长日记 > HTML > 正文

图片 onerror

2012-10-02   来源:站长日记       编辑:沧海桑田   类别:HTML    转载到:    发表评论

如果网页上图片不存在时将触发onerror事件,显示后面指定的 图片 如 /public/images/common/noemail.jpg

thinksns爱好者
要显示//www.gravatar.com/avatar.php?gravatar_id=67138854fb7b05744ff87e59bea9a876&size=60&default=http%3A%2F%2Fwww.myimkkk.com%2Fpublic%2Fimages%2Fcommon%2Fnoemail.jpg

如果图片不存在时将触发onerror事件,显示后面指定的/public/images/common/noemail.jpg
有时候,一些问题的解决方法 还是的去看官方文档
I am using the following method to replace missing images with a placeholder img. Works fine, except in Firefox. Any ideas why FF doesn't detect the error?

$(function(){     $('#id img').error(function() {         $(this).attr('src','placeholder.jpg');     }); }); Also tried .bind('error', handler) with the same results.
Are you working locally?
Docs say it might not work when using local...
//api.jquery.com/error/
In Firefox imgObject.onerror handler is intentionally killed in any form, even for hardcoded in the source elements (internal security exception raised) - maybe to prevent any possibility of content sniffing or I don't know. AFAICT nothing you can do about it. Either screw on Firefox, or move your logic server-side which is suggested: so get directory check results from server script over some ajaxoid.

52

0
52|0 | 鲜花 VS 砸蛋 | 169阅读 0评论
 
不想登录?直接点击发布即可作为游客留言。
昵称  邮箱 网站 验证码 = 1+1