[英]Javascript FileReader on IE8
I have this javascript function which shows a preview after user picked an image. 我有这个javascript函数,可在用户选择图像后显示预览。 My problem is that it's not working on IE and I do not figure out why.
我的问题是它无法在IE上运行,我也不知道为什么。
No error, but input.files is null. 没有错误,但是input.files为null。
The JavaScript 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]);
}
}
this is my HTML code 这是我的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>
As explain previously IE 8 Doesn't support FileReader API http://caniuse.com/#feat=filereader 如前所述,IE 8不支持FileReader API http://caniuse.com/#feat=filereader
But you can use a polyfill ! 但是您可以使用polyfill! Moxie can solve your problem.
Moxie可以解决您的问题。 https://github.com/moxiecode/moxie
https://github.com/moxiecode/moxie
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.