2016-02-28 64 views
0

將照片插入到請告訴我,如何將照片插入<img>,當我打開 <input type = "file">並選擇任何文件? 我該如何使用JS/JQuery?通過打開<input type =「file」>

+0

[預覽它被上傳之前的圖像(的可能的複製http://stackoverflow.com/questions/4459379/preview-an-image-before-it - 已上傳) – Aboodz

+1

[將圖片加載到](http://stackoverflow.com/questions/3814231/loading-an-image-to-a-img-from-input-file) –

回答

0

使用 '的FileReader' 對象:

$("#yourinput").change(function() { 
    var file = this.files[0]; 
    var reader = new FileReader(); 
    reader.onload = function (e) { 
     $("#yourimg").attr("src", e.target.result); 
    } 
    reader.readAsDataURL(file); 
}); 
+0

謝謝!!!!!!! – Spiderman5

+0

歡迎您;) – MBN

相關問題