预填充 HTML 表单文件输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16365668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pre-Populate HTML form file input
提问by Luigi Siri
I have a VBScript that goes over an HTML form, fills it with fixed values and then submit it. It works fine so far, but now i need to set the location of a file that is going to be uploaded within the form data.
我有一个 VBScript,它遍历 HTML 表单,用固定值填充它,然后提交它。到目前为止它工作正常,但现在我需要设置要在表单数据中上传的文件的位置。
I believed if I set the location on the value it was going to work, but it doesn't.
我相信如果我将位置设置在它将起作用的值上,但事实并非如此。
<input type='file' name="file_field" value='file_location'/>
Also, I found thiswhile researching. It says...
另外,我在研究时发现了这一点。它说...
input type=fileValue: Sets or retrieves the displayed value for the control object. This value is returned to the server when the control object is submitted.
input type=file Value:设置或检索控件对象的显示值。当控制对象被提交时,这个值被返回给服务器。
Is there a way (by code) to fill that input, even with jQuery?
有没有办法(通过代码)来填充该输入,即使使用 jQuery?
回答by Igor Popov
No. This is not possible.
不,这是不可能的。
Browsers block against setting the value attribute on input of file type for security reasons so that you can't upload a file without the user's selected any file itself.
出于安全原因,浏览器会阻止在输入文件类型时设置 value 属性,这样您就无法在没有用户选择任何文件本身的情况下上传文件。