jsp页面上img的onerror属性
2015-11-10 14:17
274 查看
直接贴代码:
<c:choose>
<c:when test="${fn:contains(item.shopPic, 'http://121.40.129.68:8080')}">
<img src="${fn:replace(item.shopPic, 'http://121.40.129.68:8080', 'http://7xlv3q.com2.z0.glb.qiniucdn.com')}" onerror="this.onerror='';this.src='${item.shopPic }'">
</c:when>
<c:otherwise>
<img src="http://7xlv3q.com2.z0.glb.qiniucdn.com${item.shopPic }" onerror="this.onerror='';this.src='${item.shopPic }'">
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${fn:contains(item.shopPic, 'http://121.40.129.68:8080')}">
<img src="${fn:replace(item.shopPic, 'http://121.40.129.68:8080', 'http://7xlv3q.com2.z0.glb.qiniucdn.com')}" onerror="this.onerror='';this.src='${item.shopPic }'">
</c:when>
<c:otherwise>
<img src="http://7xlv3q.com2.z0.glb.qiniucdn.com${item.shopPic }" onerror="this.onerror='';this.src='${item.shopPic }'">
</c:otherwise>
</c:choose>
if(item.shopPic.indexOf("http://121.40.129.68:8080")>=0){ html += '<img src="'+item.shopPic.replace("http://121.40.129.68:8080","http://7xlv3q.com2.z0.glb.qiniucdn.com") +'" onerror="this.onerror="";this.src="'+item.shopPic +'"">'; }else{ html += '<img src="http://7xlv3q.com2.z0.glb.qiniucdn.com'+item.shopPic +'" onerror="this.onerror="";this.src="'+item.shopPic +'"">'; }
解决的方法也很简单,在重新给img的src属性赋值时,先将onerror事件清除掉,再赋值,这样就不存在循环调用的问题了,代码段如下: <img src="http://img1.soufunimg.com/agents/2011_01/08/62/78/sh/houseinfo/408971808300_s22.jpg" onerror="this.onerror='';this.src='http://img1.soufunimg.com/agents/2011_01/08/62/78/sh/houseinfo/4089718083001_s.jpg'" />
相关文章推荐
- js函数细节
- highcharts 结合phantomjs纯后台生成图片
- JS日期+1格式化成yyyy-MM-dd
- jsonp 已测试
- js_碰壁反弹效果
- Json自学新得
- js内容
- JavaScript获取数组最小值和最大值的方法
- maven引入json各种版本
- 浅谈jsp、freemarker、velocity区别
- javascript字符串与数组转换汇总
- Javascript高级程序设计——语法、关键字、保留字、变量、数据类型
- javascript 动态创建tip图片提示
- javascript this指针指向?
- json数据发送时浏览器提示“保存”解决
- js倒计时 重发 效果
- js倒计时 重发 效果
- 页面加载完毕后滚动到指定位置
- 关于js中单引号(')和双引号(")的使用以及转义的理解
- js在table指定tr行上或底下添加tr行