我已经编写了下面的代码以使用文件API显示来自本地文件的文本,但是当我单击按钮时,没有任何反应,并且在检查元素时出现以下错误浏览器,我什么东错了?参数不是'Blob'类型
Uncaught TypeError: Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'.
<!DOCTYPE html>
<html>
<body>
<p>This example uses the addEventListener() method to attach a click event to a button.</p>
<button id="myBtn">Try it</button>
<pre id="file"></pre>
<script>
document.getElementById("myBtn").addEventListener("click", function(){
var file = "test.txt"
var reader = new FileReader();
document.getElementById('file').innerText = reader.result;
reader.readAsText(file);
});
</script>
</body>
</html>
'的typeof文件== “字符串” // TRUE' – Jonathan