我对JavaScript有点陌生。
我将有一个文件上传字段。我想在文件上传字段中添加一个onclick
,以添加额外的文件上传字段。
所以我想这样写:
i=0
function addfile() {
document.getElementById("form_name").appendChild(<input type="file" name="file1"" + "i++" + " />)}
…然后…
<input type="file" onclick="addfile();" />
(我知道这个语法可能是可怕的/缺少的东西,我只是试图布局我认为我应该使用的概念。)
你能让这个工作吗?
这封装了i
变量。
(function() {
var i = 0;
window.addfile = function() {
var input = document.createElement('input');
input.type = 'file';
input.name = 'file' + i++;
document.getElementById('form_name').appendChild(input);
}
})();
jsFiddle .