jQuery实现上传图片前预览效果功能

代码如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>jQuery上传图片之前可以预览效果</title>

<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>

<style>

</style>

</head>

<body>

<input id="file" ;="" onchange="c()" type="file"><br>

<img src="" id="show" width="200"><script>

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>

</body>

</html>

猜你喜欢

转载自blog.csdn.net/aa19891204/article/details/81938500