gpt4 book ai didi

javascript - 在 onChange 事件中调用 2 个函数

转载 作者:可可西里 更新时间:2023-11-01 01:47:41 26 4
gpt4 key购买 nike

我的组件有点卡住了,我需要从 props 调用 onChange

<input type="text" value={this.state.text} onChange={this.props.onChange} />

同时调用组件中的另一个函数 handleChange() 来更新 state.text,我试过了

 <input type="text" value={this.state.text} onChange={this.props.onChange; this.handleChange} />

但这似乎不起作用。

最佳答案

您可以通过将两个函数放在双引号中来实现:

<input type="text" value={this.state.text} onChange="this.props.onChange(); this.handleChange();" />

这应该有效。但如果您在第一个函数中调用第二个函数会更好:

function testFunction() {
onChange();
handleChange();
}

关于javascript - 在 onChange 事件中调用 2 个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35435611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com