我有一个文件输入元素,需要在用户浏览并选择要上传的文件后进行克隆。我开始使用 obj.cloneNode() ,一切正常,直到我尝试在 IE 中使用它。
此后我尝试使用 jQuery 的克隆方法,如下所示:
var tmp = jQuery('#categoryImageFileInput_'+id).clone();
var clone = tmp[0];
在 FireFox 中按预期工作,但在 IE 中又不行。
我被困住了。有人有一些建议吗?
猜测您需要此功能,以便您可以克隆输入元素并将其放入隐藏表单中,然后将其发布到隐藏的 iframe...
IE 的 element.clone() 实现不会继承 input type="file" 的值,因此您必须采取相反的方式:
// Clone the "real" input element
var real = $("#categoryImageFileInput_" + id);
var cloned = real.clone(true);
// Put the cloned element directly after the real element
// (the cloned element will take the real input element's place in your UI
// after you move the real element in the next step)
real.hide();
cloned.insertAfter(real);
// Move the real element to the hidden form - you can then submit it
real.appendTo("#some-hidden-form");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)