预览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

相关文章:

  • 2021-06-12
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-11-15
  • 2021-07-26
  • 2021-12-26
猜你喜欢
  • 2021-05-09
  • 2021-06-25
  • 2022-12-23
  • 2022-01-27
  • 2021-06-13
  • 2022-01-16
  • 2021-08-08
相关资源
相似解决方案