最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - <img src="image_not_found.jpg" onError="this.style.display = 'none&#3

programmeradmin2浏览0评论
<img src="image_not_found.jpg" onError="this.style.display = 'none';" alt="" />

The above code does not work in chrome, after deleting still shows image not found. But it works in firefox, what else should i add to make it work in chrome. Mine is a php website

<img src="image_not_found.jpg" onError="this.style.display = 'none';" alt="" />

The above code does not work in chrome, after deleting still shows image not found. But it works in firefox, what else should i add to make it work in chrome. Mine is a php website

Share Improve this question edited Nov 4, 2013 at 6:10 Josh Lee 178k39 gold badges277 silver badges281 bronze badges asked Nov 4, 2013 at 6:07 AparnaAparna 111 gold badge1 silver badge4 bronze badges 6
  • Are you sure it works in FF? FF hides not-found images by default anyway, if they don't have alt attribute or it's empty. – Teemu Commented Nov 4, 2013 at 6:12
  • 2 The result should be nothing, which is what I'm getting in Chrome: jsfiddle/L8xvE – Rhyono Commented Nov 4, 2013 at 6:13
  • @Teemu There isn't one. – Rhyono Commented Nov 4, 2013 at 6:23
  • <img class="example-image" src="../<?php echo $ongoing_gal_home[$i]['thumb']; ?>" onError="this.style.display = 'none';" alt="" /></a> still it shows image not found??? – Aparna Commented Nov 4, 2013 at 6:27
  • 1 You've the onerrors attached to a elements instead of img elements on your page... – Teemu Commented Nov 4, 2013 at 6:55
 |  Show 1 more ment

2 Answers 2

Reset to default 4

Try small letters:

onerror="this.style.display = 'none'"

This might be of help if you want to style 'onerror' or broken images. It really resolved an issue I battled with for a while.

<img src="/path/toimage" alt="my image" onerror="this.onerror=null;this.src='/broken-img.svg';this.classList.add('broken-img');">

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论