预览InputFile

预览InputFile

  通过input的files属性,可以取到选择的File对象,通过FileReader可以将File对象读取出来。

<body>
<input type="file" id='file'; onchange="c()">
<img src="" id='show'>
</body>
<script type="text/javascript">
function c () {
var r= new FileReader();
f=document.getElementById('file').files[0];
r.readAsDataURL(f);
r.onload=function  (e) {
document.getElementById('show').src=this.result;
};
}
</script>

参考:https://zhidao.baidu.com/question/872147854254047812.html

原文地址:https://www.cnblogs.com/tekkaman/p/7419474.html