TypeScript.未捕获的引用错误:未在HTMLInputElement.onchange中定义show



我正在尝试开发一个web应用程序,在该应用程序中,输入会获取书籍的文本文件并处理它和流行单词的数量。但是发生了以下错误:

未捕获引用错误:未在HTMLInputElement.onchange.中定义show

请帮帮我!!

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函数。

相关内容

  • 没有找到相关文章

最新更新