这是官方文档的用法:
// Callback from a <input type="file" onchange="onChange(event)">
function onChange(event) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function(event) {
// The file's text will be printed here
console.log(event.target.result)
};
reader.readAsText(file);
}
但如果我想传递一个参数给function(event){}, 应该怎么做,我试过如下定义:
var a = 1;
reader.onload = function(event, a) {
// The file's text will be printed here
console.log(event.target.result)
};
传递参数给function是你主动执行了funtion才能传递,类似onload 的触发机制其实是被动的,里面的参数也就固定了,想要在onload 里面使用其它参数就自己在外部定义,然后里面使用