javascript - 打字稿。未捕获的 ReferenceError:显示未在 HTMLInputElement.onchange 中定义
问题描述
我正在尝试开发一个网络应用程序,其中输入获取书籍的文本文件并处理它以及流行词的数量但是发生了以下错误:
未捕获的 ReferenceError:显示未在 HTMLInputElement.onchange 中定义。
请帮帮我!!
import * as _ from 'lodash';
function show(input) {
const file = input.files[0];
const reader = new FileReader();
reader.readAsText(file, 'UTF-8');
reader.onload = () => {
const res = _.words(reader.result, /[а-яА-ЯёЁa-zA-Z]{4,}/gim);
const result = _.flow([
_.countBy,
_.toPairs,
_.partial(_.orderBy, _, 1, 'desc'),
_.partial(_.take, _, 10),
]);
const txt = result(res).map(([word, num]) => `<tr><td>${word}<td>${num}`).join('');
const out = document.getElementById('out');
out.insertAdjacentHTML('beforeend', txt);
};
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>file</title>
</head>
<body>
<div>
<div id="drop-area">
Drag and drop file here
</div>
</div>
<div class="file-read">
<div class="file-input">
<label class="custom-file-upload">
<input type="file" id="input-file" onchange="show(this)" accept=".txt, .pdf, .epub, .fb2">
Upload a file
</label>
</div>
<a href="">Reset</a>
</div>
<div id="table-div">
<table id="out"></table>
</div>
</body>
</html>
解决方案
javascript 如何连接到您的 HTML?我没有看到任何脚本标签或任何东西。如果您以某种方式加载它,请告诉我们如何加载,以便我们了解错误是否是链接。如果它以某种方式链接,则可能在执行脚本之前调用了 onchange,因此尚未定义 show 函数。
推荐阅读
- python - 使用 Python 的 MIME 消息
- javascript - 无法单击文本框来更改其值
- javascript - 在 jsx 文件中从 @testing-library/react 导入“渲染”时出错
- haskell - 使用 Stack 安装 Aeson 包
- node.js - NodeJS Azure Functions - 从同一存储库的不同文件夹嵌套级别导出函数
- curl - curl和终端的新手...得到:zsh:`}'附近的解析错误
- installation - Sitecore 9.3 SIA 安装在第 2 部分失败
- java - 如何使用 mouseListener 显示数组中的内容?
- azure - 如果我必须在 Azure AKS 中计算或检索每个部署或应用程序的成本,最好的方法是什么?
- php - php:检查变量是否具有/缺少特定字符