图片上传预览

前台代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>  
        <input type="file" id="ProductImage" onchange="upload()"/>
        <img src="" id="image" />
</body>
</html>

js代码:

<script>
    function upload() {
        
        var fileReader = new FileReader();
        //取到文件的对象
        file = document.getElementById('ProductImage').files[0];
        fileReader.readAsDataURL(file);
        fileReader.onload = function (e) {          
           document.getElementById('image').src = this.result;
          
        }
    }

</script>

posted @ 2017-11-14 19:29  -小打小闹小幸福ζ  阅读(97)  评论(0)    收藏  举报