jQuery从输入类型文件多文件到输入类型文件单个文件的设置值,用于多文件上传 [英] jquery set value from input type file multifile to input type file single file for multiple file upload

查看:51
本文介绍了jQuery从输入类型文件多文件到输入类型文件单个文件的设置值,用于多文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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));

});

我正在尝试将文件多文件输入(file_change)的值设置为单个文件(myfile),

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.

我尝试过$ .each,但对如何在输入类型文件(myfile)中设置值一无所知.

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

推荐答案

无法以编程方式将文件选择为<input type="file" />.原因是安全性.考虑一下是否有可能-这意味着不道德的开发人员实际上可以通过使用Javascript选择文件并在用户不知情的情况下提交表单来从访问者计算机上窃取文件.

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.

这篇关于jQuery从输入类型文件多文件到输入类型文件单个文件的设置值,用于多文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆