js实现上传图片立即回显

<script type="text/javascript">
            //门头照片
            function newFile() {
                    var windowURL = window.URL || window.webkitURL;
                    var loadImg = windowURL.createObjectURL(document.getElementById('photoPic').files[0]);
                    document.getElementById('newImg').setAttribute('src',loadImg);
            }  
            //营业执照复印件
            function oldFile() {
                var windowURL = window.URL || window.webkitURL;
                var loadImg = windowURL.createObjectURL(document.getElementById('licensePic').files[0]);
                document.getElementById('oldImg').setAttribute('src',loadImg);
            } 
    script>
 <div class='form-div'>
                    <label class="form-label">门头照片<b>*b>label>
                    <div class="up-pic">
                        <img src="" id="newImg" > 
                        <span>+span>
                        <input type="file" id="photoPic" onchange="newFile()" name="photoPic" multiple="true" class="form-input file-pic"/>
                    div>
                div>
                 <div class='form-div'>
                    <label class="form-label">营业执照复印件<b>*b>label>
                    <div class="up-pic">
                        <img src="" id="oldImg" > 
                        <span>+span>
                        <input type="file" id="licensePic" onchange="oldFile()" name="licensePic" multiple="true" class="form-input file-pic"/>
                    div>
                div>

你可能感兴趣的:(前端,js)