如何显示所选文件的预览

时间:2013-05-07 19:17:08

标签: javascript jquery loops preview

如何显示所选文件的预览?我现在正在获取单个图像预览。我可以循环该功能吗?我已经检查过这个how to loop this function?该解决方案对我没有用.Plz帮帮我。谢谢你...

我的代码:

function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
var container = $('#mypreviewdiv');
var image = $('<img>').attr('src', e.target.result).css("width","70px").css("height","70px");
image.appendTo(container)
};
$.each(input.files,function(i) {
reader.readAsDataURL(input.files[i]);
});
}
}

我有这个HTML:

<div id="container">

<input type="file" onchange="readURL(this);"  id="fileToUpload" multiple /><br/>
<div id="total">
</div> <!-- end #total-->
<div id="mypreviewdiv" style="width:90%; height:250px; background: #FED8E7;"></div>
<button id="upload_btn">Start Uploading</button><br/>
<div class="progressbar" id="pb">
<div>
</div>    
</div>
<div id="log"></div>
<div id="status"></div>     
<div id="uplcomp"></div>
</div>

1 个答案:

答案 0 :(得分:1)

尝试更改

reader.readAsDataURL(input.files[i]);

reader.readAsDataURL(i);