以前在上傳圖片的時候,不能直接將圖片展現出來,下降了用戶的體驗度,因此找到了這個方法,上傳圖片以後,用戶能夠很直接的看到選擇的圖片this
JSP頁面展現:spa
1 <div> 2 <!--顯示要添加商品的圖片 --> 3 <input class="input1 input2 input6" type="file" name="file" onchange="showImg(this)"> 5 <img width="280px" id="getImg" > 6 7 8 </div>
JS展現:code
1 function showImg(cell){ 2 document.getElementById('getImg').src= window.URL.createObjectURL(cell.files[0]); 3 4 }