Im a little new to JavaScript.
I am going to have a file upload field. I want to add an onclick
to the file upload field to add additional file upload fields.
So I'm thinking something like:
i=0
function addfile() {
document.getElementById("form_name").appendChild(<input type=\"file\" name=\"file1\"" + "i++" + " />)}
...then...
<input type="file" onclick="addfile();" />
(I know this syntax is probably terrible/missing things, I'm just trying to layou开发者_Python百科t the concept I think I am supposed to be using.)
Can you get this working?
This encapsulates the i
variable.
(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.
精彩评论