当type ="file"时,我如何预先选择输入? [英] How can I have a preselected input for when type="file"?

查看:68
本文介绍了当type ="file"时,我如何预先选择输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:

答案&下面的注释反映了2009年旧版浏览器的状态.现在,您实际上可以在2017年使用JavaScript动态/以编程方式设置文件输入元素的值.

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 in 2017.

有关详细信息和演示,请参阅此问题的答案:
如何以编程方式设置文件输入值(即:拖放文件时)?

See the answer in this question for details as well as a demo:
How to set file input value programatically (i.e.: when drag-dropping files)?

如何设置< input> 标记,当用户提交表单时,该标记仍会显示先前选择的文件?

How can I setup an <input> tag where when the user submits the form, it will still show the previously selected file?

我尝试了以下操作:

<input type="file" name="upfile" value="<?=isset($_POST['upfile'])?$_POST['upfile']:''?>"/>

但它似乎不起作用!

推荐答案

使用输入类型文件无法设置默认值.您必须使用一些插件,例如 http://blueimp.github.io/jQuery-File-Upload/

With input type file it isn't possible to set up a default value. You have to use some plugins e.g. http://blueimp.github.io/jQuery-File-Upload/

阅读以下文章如何设置值输入到HTML中的文件?

这篇关于当type ="file"时,我如何预先选择输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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