<img cg width="100" height="100" alt='<%= model.model.Topic %>' src='<%=imgpath+"/"+model.model.Face %>h' onerror='this.src="/Styles/Expert/images/default120.gif"'/>
我这样写在ie与ff里都起作用<img cg width="100" height="100" alt='<%= model.model.Topic %>' src='<%=imgpath+"/"+model.model.Face %>h'/>
$(function() {
    $("img[cg]").attr("onerror", 'javascript:this.src="/Styles/Expert/images/default120.gif"');
});
我用js里写在ie里就不行,在ff里有些页面可以,有些页面不可以。
另外,如果src为空的话,好像也不会触发 onerror事件。。
请问要怎样解决?

解决方案 »

  1.   

    function showimg(ele) {
        ele.src = "http://cm.aqioo.com/Styles/Expert/images/default120.gif";
    }
    <img cg width="100" height="100" alt='<%= model.model.Topic %>' src='<%=imgpath+"/"+model.model.Face %>' onerror='showimg(this);' /><br />
    这是一种没办法的解决方法。。
    请问还有其他吗?
      

  2.   


    $(function() {
      $("img[cg]").attr("onerror", 'this.src="/Styles/Expert/images/default120.gif"');
    });
    这样看看,去掉javascript:
      

  3.   

    jianshao810
     
    (csdn社区) 等 级: 
    结帖率:101.30% 
    楼主结贴率可以大于100%吗神奇
      

  4.   


    $("img[cg]").bind("error",function(){
          $(this).attr("src","/Styles/Expert/images/default120.gif")
    })
      

  5.   

    $("img[cg]").bind("error",function(){ $(this).attr("src","/Styles/Expert/images/default120.gif") })在ie里也是不行
      

  6.   

    如果加载之后再绑定error的话,ie根本就不会执行onerror事件的。
    而ff就可以。。
    难道只能写到标签里面吗?
      

  7.   

    $("img[cg]").error(function(){
       this.src=yourUrl.
    })
      

  8.   

    谢谢大家都努力,应该是放到 $(function(){});
    里是不行的,可能直接在标签的下面写
    就可以。。
      

  9.   

    不可能。
    时间的加载和绑定的效果是一样的你把js放在html的最后等Dom元素加载完之后 执行绑定
      

  10.   

    是文档加载时执行和onload类似
      

  11.   

    是文档加载时执行和onload类似 意思是?
    我觉得在ie里 img 的onerror 事件比 onload事件还要早。
    不知道楼上的是不是这个意思?