我试图转换下面的函数来从窗体选择选项而不是文件输入读取文件;不熟悉JavaScript。已经做出了对我而言显而易见的改变,但是无济于事。使用FileReader与选择输入
读取服务器端文件与本地文件可能有问题吗?
function readTextFile(file, callback, encoding) {
var reader = new FileReader();
reader.addEventListener('load', function (e) {
callback(this.result);
});
if (encoding) reader.readAsText(file, encoding);
else reader.readAsText(file);
}
function fileChosen(input, output) {
if (input.files && input.files[0]) {
readTextFile(
input.files[0],
function (str) {
output.value = str;
}
);
}
}
$('#files').on('change', function() {
fileChosen(this, document.getElementById('recipients'));
});
我感谢所有帮助别人可以提供...
你可以在问题中包含'html'吗? _“从窗体选择选项读取文件”_如何将文件对象存储在'