html5中怎么实现图片上传预览功能

今天就跟大家聊聊有关html5中怎么实现图片上传预览功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

<!DOCTYPE html><html lang="zh-cn"><head><meta charset="utf-8" /><meta name="author" content="EdieLei" /><title>HTML5 图片上传预览</title><script type="text/javascript" src="<a href="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script">http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script</a>><script type="text/javascript">$(function(){    $('#img').change(function(){        var file = this.files[0];    //选择上传的文件        var r = new FileReader();        r.readAsDataURL(file);    //Base64        $(r).load(function(){            $('div').html('<img src="'+ this.result +'" alt="" />');        });    });});</script></head><body><h4>HTML5 图片上传预览</h4><input id="img" type="file" accept="image/*" /><div></div></body></html>

看完上述内容,你们对html5中怎么实现图片上传预览功能有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。