search

Home  >  Q&A  >  body text

javascript - How to assign remote files to input files?

How to

<input type="file">

I get the file URL through ajax and assign a value to the files attribute of the input. It has the same effect as clicking the input to select a local file. How to do it?

phpcn_u1582phpcn_u15822792 days ago568

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 13:25:13

    $.ajax(...,function(url){
        var a =document.createElement("A");    
        a.innerHTML = 'Link';
        a.setAttribute("href",url);
        document.body.appendChild(a);
    })

    reply
    0
  • Cancelreply