<img id="uploadPreview" style="width: 100px; height: 100px;" />
<input id="uploadImage" type="file" name="myPhoto" />
$(document).ready(function (e) {
$("#uploadImage").change(function(){
var ua = navigator.userAgent;
if(ua.indexOf("MSIE")>-1)//IE浏览器
{
document.getElementById("uploadPreview").src=document.getElementById("uploadImage").value;
}
else
{
//支持html5 中的写法
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
}
});
});
HTML5图像预览,Html Input File Preview 选择后立即预览 兼容IE,Firefox,Chorom等主流浏览器
最新推荐文章于 2025-05-22 11:07:12 发布