Clone a file input element in Javascript

后端 未结 4 1538
囚心锁ツ
囚心锁ツ 2020-11-28 11:55

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,

4条回答
  •  佛祖请我去吃肉
    2020-11-28 12:32

    You can apply other method. You have to send real element to an iframe and cloned elements insert to form. For example:

    $("INPUT[type='file']").each
    (
        function(index, element)
        {
        $(this).wrap("
    "); var Div = $(this).parent(); $(this).appendTo("FORM[name='forIframe']"); // This form for iframe Div.append($(this).clone()); } );

    If you use this method your form will send file to a server, but only one note, in Chrome an IE inputs with files is reseted.

提交回复
热议问题