Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

javascript - 如何为HTML输入的文件设置值?(How to set a value to a file input in HTML?)

Note:(注意:)

The answers & comments below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript and a dataTransfer or FileList object in 2017.(下面的答案和评论反映了2009年旧版浏览器的状态。现在,您实际上可以在2017年使用JavaScript和dataTransfer或FileList对象动态/以编程方式设置文件输入元素的值。) See the answer in this question for details as well as a demo:(有关详细信息和演示,请参见此问题的答案:)
How to set file input value programatically (ie: when drag-dropping files)?(如何以编程方式设置文件输入值(即:拖放文件时)?)

How can I set the value of this?(如何设置此值?)

<input type="file" />   ask by Alon Gubkin translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You cannot due to security reasons.(由于安全原因,您不能。)

Imagine:(想像:) <form name="foo" method="post" enctype="multipart/form-data"> <input type="file" value="c:/passwords.txt"> </form> <script>document.foo.submit();</script> You don't want the websites you visit to be able to do this, do you?(您不希望所访问的网站能够做到这一点,对吗?) =)(=))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...