Skip to content

Instantly share code, notes, and snippets.

@gaecom
Created November 21, 2013 03:39
Show Gist options
  • Save gaecom/7575740 to your computer and use it in GitHub Desktop.
Save gaecom/7575740 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
</body>
</html>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList对象
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes, last modified: ',
f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
'</li>');
}
$('#list').html('<ul>' + output.join('') + '</ul>');
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment