当前位置: 首页 > 图文教程 > 网络编程 > Javascript > img标签中onerror用法

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 img标签中onerror用法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 520 ::
收藏到网摘: n/a

可是这会引起再因网络原因或其他原因使图片不能正常加载的话 这样就是再次调用onerror,基于微软的一套核心的浏览器就会认为这是死循环 今日见一TX在HTML中写了以下代码<img src="xxx.jpg" onerror="this.src='xxx.jpg'" />
哎! 在FF上面还可以 但是在IE上面就不的,因为B/S结构有很多因素引发onerror,此处在发生onerror的时候给当前图片重新制定个地址
可是这会引起再因网络原因或其他原因使图片不能正常加载的话 这样就是再次调用onerror,基于微软的一套核心的浏览器就会认为这是死循环
然后就会报 stack overflow 的错误。
解决方案:
使用两个<img />
复制代码 代码如下:

<style type="text/css">
.hidden {
display: none;
}
</style>
<img src="xxx.jpg" onerror="this.class='hidden';xx.class=''" />
<img src="xxx.jpg" class="hidden" />