图片上传预览js

    <!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title><script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
        
            $(function(){
            
                function preView(preDIV){    
                var files=preDIV.files;
                for (var i = 0; i < files.length; i++) {
                    var data=URL.createObjectURL(files[i]);
                    $('<img class="img-item" src="'+data+'" />').appendTo( $("#upload") );
                }
            }
                
                $(':file').change(function(){console.log(this);
                    preView(this);    
                });
            });
            
        </script>
    </head>

    <body>
        <div id="upload">

        </div>
        <input type="file" value="选择图片" multiple="multiple"/>
    </body>

</html>

 

posted @ 2017-03-08 16:18  幕三少  阅读(217)  评论(0编辑  收藏  举报