img的onerror方法在Firefox中的坑,imgonerrorFirefox

來源:互聯網
上載者:User

img的onerror方法在Firefox中的坑,imgonerrorFirefox

下面的頁面在Firefox中開啟時無圖片顯示

<html><head lang="en">    <meta charset="UTF-8">    <title></title>    <script src="http://123.57.250.51/static/js/jquery-1.11.1.js" type="application/javascript"></script>    <script type="application/javascript">        window.onload= function () {            $('#headLogo')[0].onerror = function(){                console.log("onerror 136line");                this.src =  'https://www.baidu.com/img/bdlogo.png';            };            $('#headLogo').attr('src' ,'');        }    </script></head><body><img id="headLogo" ></body></html>

但是在chrome中開啟會顯示如下介面:

但是把$(‘#headLogo’).attr(‘src’ ,”); 改為

 $('#headLogo').attr('src' ,'a');

在Firefox中是好使的,即執行了onerror方法.可以看看Firefox的控制台資訊:

總結:在Firefox中,設定圖片的src為空白字串,不會觸發onerror方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.