下面的页面在火狐中打开时无图片显示
<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');
在火狐中是好使的,即执行了onerror方法.可以看看火狐的控制台信息:
总结:在火狐中,设置图片的src为空字符串,不会触发onerror方法