javascript - 将“事件”值从 html 文件传递到 js 文件
问题描述
如何将“事件”值从 html 文件传递到 js 文件。因为在 js 中,它没有定义事件和 openFile 变量。
html文件:
<form>
<input type='file' id="poem" accept='text/plain' onchange='openFile(event)' >
</form>
.js 文件:
function printPoem(event) {
var openFile = function(event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function() {
var text = reader.result;
}
}
}
解决方案
您需要this
从 HTML 传递,例如:
<form> <input type='file' id="poem" accept='text/plain' onchange='openFile(this)'></form>
推荐阅读
- html - 无法使用引导程序设置相对于 div 的屏幕高度的最大高度
- c - 使用动态分配的数组时出错
- java - 如何将值从 DAO 发送回 Servlet?
- c++ - 创建巨大的文本文件——多线程是个好主意?
- php - 在 symfony 上使用自定义规范器的条件
- python - 如何使用 phonenumbers Python 库获取 df 每一行中的所有电话号码?
- linux - Linux-仅在倒数第二行添加/插入新值,使原始内容保持在同一文件中
- mongodb - MongoDB Lookup 返回一个空数组,只有在没有数据的时候
- reactjs - ReactJS:将简单的对象道具传递给组件
- reactjs - 无法更新嵌套状态反应