<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="file" id="files" name="files[]" multiple="">
<img src="" id="show_pic">
</body>
<script>
if (window.File && window.FileReader && window.FileList && window.Blob){
function handleFileSelect(evt) {
var files = evt.target.files, f = files[0];
if (!/image\/\w+/.test(f.type)){
alert("请确保文件为图像类型");
return false;
}
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var show_pic = document.getElementById("show_pic");
show_pic.src = e.target.result;
};
})(f);
reader.readAsDataURL(f);
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
}else{
alert('该浏览器不全部支持File APIs的功能');
}
</script>
</html>
这段代码能上传一个略缩图,现在的情况是 可能会有多个略缩图需要上传,与之对应的
input type="file" id="files" name="files[]" multiple="">
<img src="" id="show_pic">
也有多个,但是具体有多少个不确定,请问如何修改这段代码?
javascript客户端图片预览,兼容最新firefox,chrome和IE11
http://blog.csdn.net/github_37125043/article/details/72723037