码迷,mamicode.com
首页 > 其他好文 > 详细

异步加载图片

时间:2016-12-10 16:34:18      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:new   blog   not   url   图片   could not   nload   javascrip   return   

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.clickBox{width:100px;height:20px;border:1px solid red;}
</style>
</head>

<body>

<script type="text/javascript">
var can="http://s1.hao123img.com/resource/site/img/logo.6456fa5.gif";
function D(url){
return new Promise(function(resolve, reject) {
var image = new Image();

image.onload = function() {
resolve(image);
};

image.onerror = function() {
reject(new Error(‘Could not load image at ‘ + url));
};

image.src = url;
});
}

D(can).then(function(value) {
alert(‘老二‘);
document.body.appendChild(value);
alert(‘老三‘);
});

alert(‘老大‘);


</script>
</body>
</html>

 

异步加载图片

标签:new   blog   not   url   图片   could not   nload   javascrip   return   

原文地址:http://www.cnblogs.com/taoxiaodan/p/6155791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!