我找到了这些代码片段http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-selecting-files-input我想看看它们是如何工作的,但代码在我的情况下不起作用. 也许我在集成方面做错了什么?请分享一些集成片段,因为我是 JS 的新手 :)
这是我可能错误的整合...
<html>
<head>
<script language="javascript" type="text/javascript">
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
} else {
alert('The File APIs are not fully supported in this browser.');
}
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// 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>', f.name, '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes, last modified: ',
f.lastModifiedDate.toLocaleDateString(), '</li>');
}
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</head>
<body>
<div>
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
</div>
<body>
</html>
PS> 我的网络浏览器:FF 5.0
感谢所有有用的评论:)