我想在一个文件上传区内,实现多个文件的上传
比如
<input type=file>..
在这一个"文件"类型的输入框后点击浏览,可以选中多个文件,并且最后上传时可以把所有选中的文件全部上传
该如何实现?
目前我没办法选中多个文件
比如
<input type=file>..
在这一个"文件"类型的输入框后点击浏览,可以选中多个文件,并且最后上传时可以把所有选中的文件全部上传
该如何实现?
目前我没办法选中多个文件
当你选择了一个文件后,使用JS新建一个新的file输入框,并将原来的输入框设置为hidden
jquery有个uplodify插件可以实现(它是借助的flash)。
<input type="file" name="file[]"><input type="button" value=" + " onclick="createFile()">
<div id="create"></div><br>
<input type="submit" value="提交">
</form><script>
function createFile(){
var root = document.getElementById("create");
var span = document.createElement("span");
var id = "span"+parseInt(Math.random()*100+Math.random()*100);
while(document.getElementById(id) == "[object]"){
id = "span"+parseInt(Math.random()*100+Math.random()*100);
}
span.id = id; var file = document.createElement("input");
file.type = "file";
file.name = "file[]"; var button = document.createElement("input");
button.type = "button";
button.value = " - ";
if(document.addEventListener){
button.addEventListener('click', function(){span.innerHTML = "";}, false);
}else if(attachEvent){
button.attachEvent('onclick', function(){span.innerHTML = "";});
} var br = document.createElement("br"); span.appendChild(file);
span.appendChild(button);
span.appendChild(br);
root.appendChild(span);
}
</script>
就用这个吧