function ii(obj){
//解决C:\fakepath问题
var oFReader = new FileReader();
var file =obj.files[0];
oFReader.readAsDataURL(file);
oFReader.onloadend = function(oFRevent){
var src = oFRevent.target.result;
$('#turn_img').attr('src',src);
}
//判断图片格式
var fileName=obj.value;
var suffixIndex=fileName.lastIndexOf(".");
var suffix=fileName.substring(suffixIndex+1).toUpperCase();
if(suffix!="BMP"&&suffix!="JPG"&&suffix!="JPEG"&&suffix!="PNG"&&suffix!="GIF"){
alert( "请上传图片(格式BMP、JPG、JPEG、PNG、GIF等)!");
}
//解决C:\fakepath问题
var oFReader = new FileReader();
var file =obj.files[0];
oFReader.readAsDataURL(file);
oFReader.onloadend = function(oFRevent){
var src = oFRevent.target.result;
$('#turn_img').attr('src',src);
}
//判断图片格式
var fileName=obj.value;
var suffixIndex=fileName.lastIndexOf(".");
var suffix=fileName.substring(suffixIndex+1).toUpperCase();
if(suffix!="BMP"&&suffix!="JPG"&&suffix!="JPEG"&&suffix!="PNG"&&suffix!="GIF"){
alert( "请上传图片(格式BMP、JPG、JPEG、PNG、GIF等)!");
}
}
HTML
<img id="turn_img" src="" />
<input type="file" id="file" name="file_name" class="input w300" οnchange="ii(this);"/>
评论 (0)