File API

1 FileList objects and file objects

 

concept:

 FileList object represents the list of files selected by the user. In the HTML4, the file control only allow placement of a document but to HTML5 by adding mutiple attribute file allows the placement of multiple files. Within the control of each user-selected file is a file object, and the object was FileList list of these file objects, on behalf of all the files selected by the user.

 

application:

Code

<script language="JavaScript">
function ShowFileName(){
var file;
//doucument.getElementByld("file").files返回FileList文件列表对象
for(var i=0;i<doucument.getElementById("file").files.length;i++)
{
file = document.getElementByd("file").files[i];
alert(file.name);
}
}

</script>
<body>
选择文件:
<input type="file" id="file" multiple size="80"/>
<input type="button" onclick="ShowFileName();" value="文件上传"/>
</body>

 

display

 

Guess you like

Origin www.cnblogs.com/yanyanstyle/p/11280219.html