我需要将multiple
属性添加到输入类型file
但我不知道该怎么做。
在我的代码下面:
var input = document.createElement("input");
input.type = "file";
input.id = "files" + af;
input.name = "imgs[]";
input.className = "upload";
但我需要输入具有多个
属性。
最佳答案
只需使用 setAttribute()
函数,如下例所示:
var af = 1;
var input = document.createElement("input");
input.setAttribute("type","file");
input.setAttribute("id" ,"files" + af);
input.setAttribute("name","imgs[]");
input.setAttribute("multiple","");
input.className = "upload";
console.log(input);
关于javascript - 如何将 "multiple"属性添加到动态生成的输入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42763654/