jquery set value from input type file multifile to input type file single file for multiple file upload

大兔子大兔子 提交于 2019-12-24 14:17:58

问题


<form id="myForm" enctype="multipart/form-data" method="POST" 
                                     onSubmit="return form_submit();">
   <input type="file"  name="myfile" id="myfile_main" />

</Form>

Javascript

$("#file_change").change(function(){

    var file=this.files;

    var obj=$.parseJSON(file);

    alert(JSON.stringify(this.files));

});

I am trying to set values from file multifile input (file_change) to a single file (myfile),

my main motive is to select multiple file and upload one by one by self.

I am getting error while setting the each value from multifile input to single file input.

I had tried $.each but not getting any idea about how to set the value in input type file (myfile).


回答1:


It is not possible to programatically select files into a an <input type="file" />. The reason for this is security. Consider if it was possible - it would mean that unscrupulous developers could essentially steal files from visitors computers by using Javascript to select a file and submit the form without the user knowing.



来源:https://stackoverflow.com/questions/17162569/jquery-set-value-from-input-type-file-multifile-to-input-type-file-single-file-f

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!