Skip to content

Instantly share code, notes, and snippets.

@alanerzhao
Created May 28, 2014 08:11
Show Gist options
  • Select an option

  • Save alanerzhao/fcf29d3df2e472152736 to your computer and use it in GitHub Desktop.

Select an option

Save alanerzhao/fcf29d3df2e472152736 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
// multiple属性可以让用户能选择多个文件
<input id="myfiles" multiple type="file">
<input type="button" id="btn" value="Btn"/>
</body>
<script>
var pullfiles=function(){
// 获取到input元素
var fileInput = document.querySelector("#myfiles");
var btn = document.querySelector("#btn");
files = fileInput.files;
// 获取到所选文件数量
fl=files.length;
var i=0;
while ( i < fl) {
var file = files[i];
i++;
}
}
// 设置change事件处理函数
document.querySelector("#myfiles").onchange=pullfiles;
btn.onclick = function () {
console.log(fl.splice())
}
</script>
</html>
//files add item remoe
var newList = []
for(var i = 0; i < files.length; i++)
{
newList.push(files.item(i));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment