日期:2014-05-16 浏览次数:20305 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
div
{
width: 500px;
height: 500px;
background-image: url(0.png);
background-color: #000000;
}
</style>
</head>
<body>
<div id="div"></div>
<script type="text/javascript">
window.onload = function(){
var img=new Image();
img.src='0.png';
console.log(img)
if(img.width==0){
alert('图片加载失败')
}else{
alert('图片加载成功')
}
}
</script>
</body>
</html>
$('<img/>').attr('src', 'http://picture.de/image.png').load(function() {
$(this).remove(); // prevent memory leaks as @benweet suggested
$('body').css('background-image', 'url(http://picture.de/image.png)');
});