HTML文件上传

时间:2015-09-24 05:10:21

标签: javascript 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>

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

1 个答案:

答案 0 :(得分: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);
}