问题描述
我有一个文件输入元素,需要在用户浏览并选择要上传的文件后进行克隆.我开始使用 obj.cloneNode() 并且一切正常,直到我尝试在 IE 中使用它.
I have a file input element that needs to be cloned after the user has browsed and selected a file to upload. I started by using obj.cloneNode() and everything worked fine, that is until I tried using it in IE.
我已经尝试使用 jQuery 的 clone 方法如下:
I've since tried using jQuery's clone method as follows:
var tmp = jQuery('#categoryImageFileInput_'+id).clone();
var clone = tmp[0];
在 FireFox 中可以正常工作,但在 IE 中又不行.
Works as expected in FireFox, but again not in IE.
我被卡住了.有人有什么建议吗?
I'm stuck. Anyone have some suggestions?
推荐答案
编辑文件表单字段存在安全风险,因此在大多数浏览器上被禁用,应该在 firefox 上被禁用.依赖此功能不是一个好主意.想象一下,如果有人能够使用 javascript 将隐藏的文件上传字段更改为,比如说,
Editing the file form field is a security risk and thus is disabled on most browsers and should be disabled on firefox. It is not a good idea to rely on this feature. Imagine if somebody was able, using javascript, to change a hidden file upload field to, lets say,
c:UsersPersonDocumentsFinances
c:UsersPersonDocumentsFinances
或
C:UsersPersonAppDataMicrosoftOutlook.pst
C:UsersPersonAppDataMicrosoftOutlook.pst
:)
这篇关于在 Javascript 中克隆文件输入元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!