下面是一個(gè)簡(jiǎn)單的demo,把圖片上傳的時(shí)候顯示到瀏覽器,很抱歉不能直接粘貼代碼乳愉,只能截圖貼出來(lái)
function fileSelected() {
var oFile = document.getElementById('image_file').files[0];
// get preview element
var oImage = document.getElementById('preview');
// prepare HTML5 FileReader
var oReader = new FileReader();
oReader.onload = function(e) {
// e.target.result contains the DataURL which we will use as a source of the image
oImage.src = e.target.result;
};
// read selected file as DataURL
oReader.readAsDataURL(oFile);
}
圖片是html钙畔,下面是js代碼,一個(gè)小的demo就完成了