1 に答える
0
この動作デモを試してください
function readSingleFile(evt) {
var f = evt.target.files[0];
console.log(f);
if (!f) {
alert("Failed to load file");
return;
}
if (f.name.indexOf('.txt') == -1) {
alert(f.name + " is not a valid text file.");
return;
}
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
alert( "Got the file.n"
+"name: " + f.name + "n"
+"type: " + f.type + "n"
+"size: " + f.size + " bytesn"
+ "contents: " + contents
);
document.getElementById('board').innerHTML = contents;
}
r.readAsText(f);
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
于 2013-09-28T09:47:06.063 に答える