Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在弹出窗口中显示图像_Javascript_Html_Filereader_Fileapi - Fatal编程技术网

Javascript 如何在弹出窗口中显示图像

Javascript 如何在弹出窗口中显示图像,javascript,html,filereader,fileapi,Javascript,Html,Filereader,Fileapi,我已经使用javascript函数在内存中读取了一个图像。现在我需要在弹出窗口中显示此图像,当在现有页面中单击按钮时,弹出窗口将打开 我该怎么做?是否有任何方法可以从内存中读取图像,然后将其显示在新的弹出窗口中?检查此项- 似乎它有您需要的示例: <style> .thumb { height: 75px; border: 1px solid #000; margin: 10px 5px 0 0; } </style> <input

我已经使用javascript函数在内存中读取了一个图像。现在我需要在弹出窗口中显示此图像,当在现有页面中单击按钮时,弹出窗口将打开

我该怎么做?是否有任何方法可以从内存中读取图像,然后将其显示在新的弹出窗口中?

检查此项-

似乎它有您需要的示例:

<style>
  .thumb {
    height: 75px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
</style>

<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }

      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

.拇指{
高度:75px;
边框:1px实心#000;
利润率:10px 5px 0;
}
功能手柄文件选择(evt){
var files=evt.target.files;//文件列表对象
//循环浏览文件列表并将图像文件渲染为缩略图。
for(var i=0,f;f=files[i];i++){
//仅处理图像文件。
如果(!f.type.match('image.*')){
持续
}
var reader=new FileReader();
//闭包以捕获文件信息。
reader.onload=(函数(文件){
返回函数(e){
//渲染缩略图。
var span=document.createElement('span');
span.innerHTML=['').join('');
document.getElementById('list').insertBefore(span,null);
};
})(f) );
//作为数据URL读入图像文件。
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change',handleFileSelect,false);
只需将该div替换为所需的弹出窗口

检查此项-

似乎它有您需要的示例:

<style>
  .thumb {
    height: 75px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
</style>

<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }

      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

.拇指{
高度:75px;
边框:1px实心#000;
利润率:10px 5px 0;
}
功能手柄文件选择(evt){
var files=evt.target.files;//文件列表对象
//循环浏览文件列表并将图像文件渲染为缩略图。
for(var i=0,f;f=files[i];i++){
//仅处理图像文件。
如果(!f.type.match('image.*')){
持续
}
var reader=new FileReader();
//闭包以捕获文件信息。
reader.onload=(函数(文件){
返回函数(e){
//渲染缩略图。
var span=document.createElement('span');
span.innerHTML=['').join('');
document.getElementById('list').insertBefore(span,null);
};
})(f) );
//作为数据URL读入图像文件。
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change',handleFileSelect,false);
只需将该div替换为所需的弹出窗口