简体   繁体   English

如何同时预览多张图片?

[英]how to preview many pictures in a same time?

I wrote this code but I can only preview one image but I want to preview multiple images at a same time.我写了这段代码,但我只能预览一个图像,但我想同时预览多个图像。 here is my code这是我的代码

 var loadFile = function(event) { var image = document.getElementById('output'); image.src = URL.createObjectURL(event.target.files[0]); };
 <p> <input type="file" accept="image/*" name="image" id="file" onchange="loadFile(event)" style="display: none" /> </p> <button> <label for="file" style="cursor: pointer">Upload to Album two</label> </button> <p><img id="output" width="200" /></p>

One way is to dynamically create the image and append it to a wrapper object (in this case a paragraph) instead of using a precreated image tag.一种方法是动态创建图像和 append 到包装器 object(在本例中为段落),而不是使用预先创建的图像标签。

 var target = document.getElementById('output'); var loadFile = function (event) { var image = document.createElement('img'); image.src = URL.createObjectURL(event.target.files[0]); target.appendChild(image) };
 <p> <input type="file" accept="image/*" name="image" id="file" onchange="loadFile(event)" style="display: none" /> </p> <button> <label for="file" style="cursor: pointer">Upload to Album two</label> </button> <p id="output"></p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM