IE8上的Javascript FileReader [英] Javascript FileReader on IE8
本文介绍了IE8上的Javascript FileReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个javascript函数,在用户选择图像后显示预览。我的问题是它不能在IE上运行,我不知道原因。
I have this javascript function which shows a preview after user picked an image. My problem is that it's not working on IE and I do not figure out why.
没有错误,但input.files为空。
No error, but input.files is null.
JavaScript
The JavaScript
function showimagepreview(input, previewId) {
if (input.files && input.files[0]) {
var filerdr = new FileReader();
filerdr.onload = function (e) {
$('#' + previewId).attr('src', e.target.result);
}
filerdr.readAsDataURL(input.files[0]);
}
}
这是我的HTML代码
<div class="photo" id="photo-1">
<input type="file" class="upload-file" name="Photos[1]" onchange="showimagepreview(this, 'photosPreview1')" />
<img id="photosPreview1" class="PhotoPreview" />
</div>
推荐答案
如前所述,IE 8不支持FileReader API http://caniuse.com/#feat=filereader
As explain previously IE 8 Doesn't support FileReader API http://caniuse.com/#feat=filereader
但你可以使用polyfill!
Moxie可以解决您的问题。
https://github.com/moxiecode/moxie
But you can use a polyfill ! Moxie can solve your problem. https://github.com/moxiecode/moxie
这篇关于IE8上的Javascript FileReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文