<分区>
我正在尝试替换未找到的图像,或者宽度或高度为 1 像素的图像。我设法用 PHP 做到了这一点:
$imgName = $resultList->IMAGE1; // ex http://www.domain.com/image.png
if (@file_get_contents($imgName) && $imgName !== 'h') {
// detects the image size (NOT based on width and height attributes)
$imgNamearray = getimagesize($imgName);
$size = $imgNamearray[3];
if ($size == 'width="1" height="1"') {
$imgName = $base_path . 'uploads/no-img.jpg';
}
} else {
$imgName = $base_path . 'uploads/no-img.jpg';
}
我在 jQuery 中试过这段代码:
$('body').append('<div id="init"><img id="myimg" src="http://www.google.co.uk/intl/en_com/images/srpr/logo1w.png" /></div>');
$('#init').hide();
$('#myimg').bind("load",function(){
alert(this.height)
})
可以在此处的 fiddle 中找到 http://jsfiddle.net/WMpSy/但我是 jQuery 的菜鸟,请帮助我。非常感谢。