js图片异步加载

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title> New Document </title>

  <script>
function loadImage(url,callback){
var img = new Image();
img.src = url ;
if(img.complete){
callback.call(img);
return ;
}else{
img.onload = function(){
callback.call(img);
}
}
}

function imgLoad(){
alert(this.width);
}
  </script>
</head>

<body>
<input type="button" value="loadImage" onclick="loadImage('7407.jpg',imgLoad)" />
</body>
</html>

你可能感兴趣的:(异步加载)