zoukankan      html  css  js  c++  java
  • Clone a file input element in Javascript

    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.

    I've since tried using jQuery's clone method as follows:

    var tmp = jQuery('#categoryImageFileInput_'+id).clone();
    var clone = tmp[0];

    Works as expected in FireFox, but again not in IE. 

    Guessing that you need this functionality so you can clone the input element and put it into a hidden form which then gets POSTed to a hidden iframe...

    IE's element.clone() implementation doesn't carry over the value for input type="file", so you have to go the other way around:

    // 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"); 

  • 相关阅读:
    swagger配置
    windows下安装redis
    Redis在windows下安装过程
    jenkins安装部署全过程
    MySQL表名不区分大小写的设置方法
    Linux常用命令
    java 执行redis的部分方法
    把jar包加入本地maven库内
    Java 枚举7常见种用法
    【转】每天一个linux命令(1):ls命令
  • 原文地址:https://www.cnblogs.com/sniper007/p/2305270.html
Copyright © 2011-2022 走看看