【发布时间】:2012-07-25 22:00:24
【问题描述】:
我在这里发现了jQuery/Javascript to replace broken images之前提到的这个问题
这是最好的答案。我试过了,效果很好
function ImgError(source){
source.src = "/images/noimage.gif";
source.onerror = "";
return true;
}
<img src="someimage.png" onerror="ImgError(this);"/>
但是当我尝试在前一个函数中执行其他事件时
function ImgError(source){
source.hide(); // hide instead of replacing the image
source.onerror = "";
return true;
}
我收到了这个错误
TypeError: 'undefined' is not a function (evaluating 'source.hide()')
我尝试过的每个 jQuery 事件/方法都遇到了 TypeError。
有什么问题?
【问题讨论】:
-
你没有使用 jQuery。
标签: jquery image typeerror onerror