cn.onchange 不是函数

问题描述 投票:0回答:1

我需要调用onChange函数,并且需要在函数中传递参数。所以我就这样做

 setTimeout(function () { document.getElementById(input.key)?.onchange({}) } , 200);                       

                        }

我收到此错误:

 cn.onchange is not a function

有人可以帮助我吗?

javascript angular typescript timer
1个回答
0
投票

如果你想直接调用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" />

© www.soinside.com 2019 - 2024. All rights reserved.