html5中IE、火狐、谷歌图片上传预览
来源:互联网 发布:中山大学学生网络缴费 编辑:程序博客网 时间:2024/06/10 05:01
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>点击上传</title>
<script src="jquery-1.9.1.js"></script>
<script>
function fileSelect(){
var e=arguments.callee.caller.arguments[0]||window.event;
var files=e.target.files;//要上传的文件列表对象
var reg = /image\/.*/i; //文件格式验证
var p=document.getElementById('Preview');
var ul=document.getElementById('Errors');
var myp=document.getElementById('myprogress');
for(var i=0,f;f=files[i];i++){
if(!f.type.match(reg)) {
//设置错误信息
var li=document.createElement('li');
li.innerHTML='<li>'+f.name +'不是图片文件.</li>';
ul.appendChild(li);
continue;
}else{
var reader = new FileReader();
//文件成功读取完成时触发
reader.onload=(function(file){
return function(e){
var span =document.createElement('span');
span.innerHTML='<img src="'+this.result+'" alt="'+file.name+'" title="'+file.name+'" class="mypic"/>';
p.insertBefore(span,null);
};
})(f);
reader.onprogress=function(e){
//更新进度条
myprogress.value=(e.loaded/e.total)*100;
}
/*
onerror 出错时触发
onload 文件读取成功完成时触发
onloadend 读取完成触发,无论成功或失败
onloadstart 读取开始时触发
onprogress 读取中
*/
//读取文件内容
reader.readAsDataURL(f);
}
}
}
$(function(){
if(window.File && window.FileList && window.FileReader && window.Blob){
$("#Files").change(function(){
fileSelect();
});
//document.getElementById('Files').addEventListener('click',fileSelect,false);
}else{
document.write('您的浏览器不支持File Api');
}
});
</script>
<style>
.mypic{
width:100px;
height:120px;
margin-left:10px;
border:1px solid #F60;
}
progress{
width:800px;
height:30px;
}
</style>
</head>
<body>
<input type="file" multiple id="Files" accept="image/jpeg"/>
<ul id="Errors">
</ul>
<div id="Preview">
</div>
<progress max="100" id="myprogress" value="0"></progress>
</body>
</html>
0 0
- html5中IE、火狐、谷歌图片上传预览
- IE火狐谷歌等主流浏览器--图片上传预览
- 图片上传预览(兼容火狐和IE)
- 兼容火狐 IE的图片上传预览
- 图片上传前预览,支持IE各版本、火狐、谷歌浏览器
- 浏览器本地预览图片并Ajax上传到服务器(谷歌火狐 ,IE不兼容)
- 图片上传并预览(IE,火狐浏览器兼容问题)
- html 图片预览上传(支持ie,google,火狐)
- IE 中上传前按比例预览图片
- html5预览上传图片
- html5---图片上传预览
- Html5 上传图片预览
- HTML5上传图片预览
- 火狐 IE 实现图片本地预览 demo
- 兼容IE、谷歌Chrome、火狐Firefox的图片上传预览功能
- 兼容IE、谷歌Chrome、火狐Firefox的图片上传预览功能
- IE 图片上传并预览
- IE兼容上传图片预览
- zookeeper3.4.6分布式数据一致性服务集群在CentOS6.5上部署(何志雄)
- CSS的一些问题
- 成为嵌入式开发工程师几个步骤
- Gridview使用Footer Template 添加记录
- gitlab重置密码
- html5中IE、火狐、谷歌图片上传预览
- ubuntu下用apt-get安装apache2
- web自动保存表单
- oralce查看当前用户
- 找工作和找对象是一样一样的
- 数据分页存储过程
- js中的escape()、encodeURI()和encodeURIComponent()
- Android源码编译全过程记录(基于最新安卓5.1.0)
- 购物车Jquery的实现