Javascript 上传前预览图像?

Javascript 上传前预览图像?,javascript,image,file-upload,Javascript,Image,File Upload,在上传到服务器之前,有没有办法在html页面上预览图片 // Checking all the possible window objects needed for file api if (window.File && window.FileReader && window.FileList && window.Blob) { // Browser is fully supportive. } else { // Browser not

在上传到服务器之前,有没有办法在html页面上预览图片

// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}

我需要显示我仍然需要上传的图像的预览,只是为了显示已经做了更改。我可能只需要更改图像源。我可以使用任何现有的技术/方法吗?

看看这篇文章,并尝试一下你想在你的问题上实现的演示

// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}

这一点在现代浏览器上是可能的。

可以使用HTML5文件阅读器API实现

// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}
仅使用JavaScript和FileReader对象,我们就可以允许用户将图像加载到应用程序中

// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}
HTML代码:

<input type="file" id="getimage">
    <fieldset>
        <legend>Your image here</legend>
            <div  id="imgstore"></div>
    </fieldset>
// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}
以下是有用的参考链接:

// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}

// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}

// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}

我最近这样解决了这个问题:

// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}
readUrl = function(input) {
        //if File is there
        if(input.files && input.files[0]) {
            //create a Filereader
            var reader = new FileReader();
            //bind a function to the reader which will be executed when file is completely loaded
            reader.onload = function(e) {
                //Here you render your preview image
                $("#bild-vorschau").attr("src", e.target.result);
            }

            reader.readAsDataURL(input.files[0]);
        }
    }
我将changelistener绑定到fileinput

// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}
<input type="file" name="photofile" id="photofile">



$('#photofile').bind("change", function(){
            readUrl(this);
         });

在这里,您可以在一个

Safari中看到它,它为您提供了一些选项,但我也在寻找其他HTML浏览器,如IE、Chrome和FF
// Checking all the possible window objects needed for file api
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Browser is fully supportive.
} else {
  // Browser not supported. Try normal file upload
}