首页 > 技术文章 > 图片预览

liwentao 2016-12-14 21:25 原文


$("#fileImage").change(function(){
var fileImg = $("#image");
var explorer = navigator.userAgent;
var imgSrc = $(this)[0].value;
if (explorer.indexOf('MSIE') >= 0) {
if (!/\.(jpg|jpeg|png|JPG|PNG|JPEG)$/.test(imgSrc)) {
imgSrc = "";
fileImg.attr("src","/img/default.png");
return false;
}else{
fileImg.attr("src",imgSrc);
}
}else{
if (!/\.(jpg|jpeg|png|JPG|PNG|JPEG)$/.test(imgSrc)) {
imgSrc = "";
fileImg.attr("src","/img/default.png");
return false;
}else{
var file = $(this)[0].files[0];
var url = URL.createObjectURL(file);
fileImg.attr("src",url);
}
}
});

 

推荐阅读