简体   繁体   English

如何将现有文件选择保留在多个选择中

[英]How to keep existing file selections on multiple selections

In html we can select multiple files at once using file input control. 在html中,我们可以使用文件输入控件一次选择多个文件。 But when i selected a file second time previous files overwritten by the newly selected files. 但是当我第二次选择文件时,先前的文件被新选择的文件覆盖。

My question is, Can we able to keep existing file selections while selecting new files? 我的问题是,在选择新文件时我们能否保留现有文件选择?

I didn't get any snippet related to this, seems most people doesn't require this kind of functionality. 我没有与此相关的任何片段,似乎大多数人都不需要这种功能。 So i did it myself. 所以我自己做了。

  • created a file input control 创建了一个文件输入控件
  • click event on this element, clones current file input with duplicate id using jquery clone method. 单击此元素上的click事件,使用jquery clone方法clone具有重复ID的当前文件输入 This cloned input control set to hidden and current input control holds latest files. 此克隆的输入控件设置为隐藏,而当前输入控件保留最新文件。
  • so, on form submit i got all the files selected 因此,在提交表单时,我选择了所有文件

I doubt how well this method works in older browsers, but current chrome and firefox executes it well. 我怀疑这种方法在较旧的浏览器中的效果如何,但是当前的chrome和firefox能否很好地执行它。

I think your problem is that you give the same name to the different <input> tags.

<div id="selectFiles">
    <input type='file' name='userFile1'>
    <input type='file' name='userFile2'>
    <input type='file' name='userFile3'>
    <input type='file' name='userFile4'>
</div>

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

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