[英]Try To Display Image onChange Event of Input File
我試圖在直接在輸入文件的onchange
事件上選擇圖像后顯示圖像,但我想出了它在所有瀏覽器中是如何完成的,但我停下了Safari嘗試獲取
inputFile.value
屬性,但是即使繞過該問題,它inputFile.value
返回我需要幫助的偽造路徑,但我不需要發回郵件。
問候
假設您的輸入和圖像如下
<img id="PreviewImage" src="" alt="?" style="height:100px;" />
<input id="ImageFileUpload" onchange="readURL(this);" type="file" runat="server"/>
function readURL(input) {
if (input.files && input.files[0]) {//Check if input has files.
var reader = new FileReader(); //Initialize FileReader.
reader.onload = function (e) {
$('#PreviewImage').attr('src', e.target.result);
$("#PreviewImage").resizable({ aspectRatio: true, maxHeight: 300 });
};
reader.readAsDataURL(input.files[0]);
}
else {
$('#PreviewImage').attr('src', "#");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.