sus*_*ani 5 javascript jquery image
jQuery('img').bind('error',function(){
alert('hi');
jQuery(this).hide();
});
我已经编写了这段代码,但是没有可用的图像没有隐藏,仍然显示交叉标志.任何人都能指出可能出错的地方.我在document.ready下写这个,我也在window.onload下尝试过.
问题似乎是,当您绑定错误事件时,图像的错误已经被触发.您可以通过在绑定事件后重置img.src来再次触发它.以下适用于IE8,FF和Chrome.
$('img').error(function(){
alert('hi');
$(this).hide();
});
$('img').each(function() { this.src = this.src; });
Run Code Online (Sandbox Code Playgroud)
jsFiddle在这里:http://jsfiddle.net/7cnQN/
| 归档时间: |
|
| 查看次数: |
4212 次 |
| 最近记录: |