我需要调用onChange函数,并且需要在函数中传递参数。所以我就这样做
setTimeout(function () { document.getElementById(input.key)?.onchange({}) } , 200);
}
我收到此错误:
cn.onchange is not a function
有人可以帮助我吗?
如果你想直接调用onchange,
const input = { key: 'foo' };
// Assign the handler...
document.getElementById('foo').onchange = (data) => {
console.log({ data });
};
setTimeout(function() {
document.getElementById(input.key).onchange({}); // Call it...
}, 1000);
<input type="text" id="foo" />