<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<input type="file" id="files" multiple />
<label id="list"></label>
<script>
//Interact with local files using the HTML5 file API
function handleFileSelect(evt)
{
//target is the element that triggered the event
var files = evt.target.files; // FileList object
// files is a FileList of File objects. List some properties.
for(var i=0; i<files.length; i++)
{
f = files[i];
document.getElementById('list').innerHTML += f.name + ' ' + f.type + ' ' + f.size + ' bytes ' + f.lastModifiedDate + '<br/>';
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</body>
</html>
我只是想知道爲什麼代碼不能正常工作,如果腳本部分從身體移動到頭部。爲什麼這隻在身體部分工作,而不在頭部
正確工作的代碼應該顯示文件名及其大小和其他詳細信息,但是當代碼被移動時,它不會顯示任何內容。
您的良好起點應該打開瀏覽器控制檯,看看錯誤是什麼......這將是非常自我解釋。 – Fallup 2015-02-08 17:59:56