在Javascript中克隆文件输入元素

在Javascript中克隆文件输入元素

本文介绍了在Javascript中克隆文件输入元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件输入元素,需要在用户浏览并选择要上传的文件后进行克隆。我开始使用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的克隆方法,如下所示:

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:\ Users \ Person \Documents \ Finance

c:\Users\Person\Documents\Finances

C:\ Users \ Person \ AppData \ Microsoft's\Outlook.pst

C:\Users\Person\AppData\Microsoft\Outlook.pst

:)

这篇关于在Javascript中克隆文件输入元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:16