2015-09-24 88 views
0

我试图采取以下方式文件输入:HTML文件上传

Input file: <input type="file" name="-f" id="fa"> 

我想补充的HTML链接(upload example),使其上传的示例文件上单击它,无需打开文件上传窗口。我试过以下内容:

<a href="" onclick="document.getElementById('fa').files[0].name = 'http://localhost/EXAMPLE/example.txt'; return false; ">(upload example)</a> 

但它不工作。我该怎么办呢?

回答

0

你为它制作FormData,现在文件[0] .name被覆盖。

<a href="" onclick="fileAppend('http://localhost/EXAMPLE/example.txt'); return false; ">(upload example)</a> 

function fileAppend(file){ 
var Form = new FormData(); 
Form.append(file); 
console.log(Form); 
}