上传图片jQuery之前的图片预览 [英] Image preview before uploading image jquery
本文介绍了上传图片jQuery之前的图片预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<!DOCTYPE html>
< html>
< head>
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js>< / script>
< script>
函数readURL(input){
if(input.files&& input.files [0]){
var reader = new FileReader();
reader.onload = function(e){
$('#img_prev')
.attr('src',e.target.result)
。宽度(150)
。高度(200);
};
reader.readAsDataURL(input.files [0]);
}
}
< / script>
< meta charset = utf-8 />
< title> JS Bin< / title>
<! - [if IE]>
< script src =http://html5shiv.googlecode.com/svn/trunk/html5.js>< / script>
<![endif] - >
< style>
文章,旁边,数字,页脚,标题,hgroup,
菜单,nav,部分{display:block; }
< / style>
< / head>
< body>
< input type ='file'onchange =readURL(this); />
< / body>
< / html>
解决方案
是的,我只有一个解决方案。 IE 9不支持文件阅读器,因此我们可以禁用文件阅读器的图像预览,以供其他浏览器使用,它可以很好地工作。
Is there any way to implement the fileReader() in IE. i searched a lot but didn't find any solution. This my code where i am trying to implement it. It's working fine in firefox and in chrome but it isn't workink in IE8 and IE9.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#img_prev')
.attr('src', e.target.result)
.width(150)
.height(200);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<input type='file' onchange="readURL(this);" />
<img id="img_prev" src="#" alt="your image" />
</body>
</html>
解决方案
yeah i got only one solution. IE 9 don't support File Reader so we can disable image preview for file reader for rest browsers it will work perfectly.
这篇关于上传图片jQuery之前的图片预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文