我試圖在html中打印文本多個文件。我成功地打印了單個文件。但是我無法打印多個文件的文本輸出。能否請你幫我糾正代碼?`使用Javascript打印多個html文件的輸出
<!DOCTYPE html>
<html>
<body>
<h1> Testing programs </h1>
<input type="file" id="fileinput" multiple />
<pre id="file-content"></pre>
<h3>Contents of the file:</h3>
<script type="text/javascript">
function readMultipleFiles(evt) {
//Retrieve all the files from the FileList object
var files = evt.target.files;
if (!files) {
for (var i=0, f; f=files[i]; i++) {
var r = new FileReader();
r.onload = (function(f) {
return function(e) {
var contents = e.target.result;
displayContents(contents);
};
});
r.readAsText(f);
}
} else {
alert("Failed to load files");
}
function displayContents(contents) {
var element = document.getElementById('file-content');
element.innerHTML = contents;
}
document.getElementById('fileinput').addEventListener('change', readMultipleFiles, false)
</script>
</body>
</html>`
非常感謝。 :) –
樂意幫忙!請[accept and up-vote](http://meta.stackexchange.com/questions/23138/how-to-accept-the-answer-on-stack-overflow)解決目的的最佳解決方案:) __快樂編碼!__ – Rayon