最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - 2 function calls into onChange - ReactJS - Stack Overflow

programmeradmin6浏览0评论

I wanna that into an OnChange, this event calls to 2 different functions with ReactJS. I have tried several forms but I have not success. I have tried:

/*This is my text area, into ONCHANGE I put options shown below*/
<textarea name="NAME" id="ID" ONCHANGE placeholder="PLACEHOLDER" maxLength="4000" rows="7" class="form-control" required></textarea> 

/*This way give me error*/
onChange={this.activarBotonEnviar this.contadorDeCaracteres}

/*This way give me error*/
onChange={this.activarBotonEnviar; this.contadorDeCaracteres}

/*This way only execute last function*/
onChange={this.activarBotonEnviar, this.contadorDeCaracteres}

/*This way only execute last function*/
onChange={this.activarBotonEnviar} onChange={this.contadorDeCaracteres}

I am working with ReactJS. I hope you could help me. Thank you all.

I wanna that into an OnChange, this event calls to 2 different functions with ReactJS. I have tried several forms but I have not success. I have tried:

/*This is my text area, into ONCHANGE I put options shown below*/
<textarea name="NAME" id="ID" ONCHANGE placeholder="PLACEHOLDER" maxLength="4000" rows="7" class="form-control" required></textarea> 

/*This way give me error*/
onChange={this.activarBotonEnviar this.contadorDeCaracteres}

/*This way give me error*/
onChange={this.activarBotonEnviar; this.contadorDeCaracteres}

/*This way only execute last function*/
onChange={this.activarBotonEnviar, this.contadorDeCaracteres}

/*This way only execute last function*/
onChange={this.activarBotonEnviar} onChange={this.contadorDeCaracteres}

I am working with ReactJS. I hope you could help me. Thank you all.

Share Improve this question edited Jul 17, 2017 at 16:29 Felix Kling 818k181 gold badges1.1k silver badges1.2k bronze badges asked Jul 17, 2017 at 16:21 JuMoGarJuMoGar 1,7603 gold badges23 silver badges51 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

How it is possible for a variable/property to hold two values at the same time?

We can assign a single function to Onchange event, so what you can do is either create a new function and call these two function from that or call one from another.

Creating new Function:

onChange = { (e) => { this.activarBotonEnviar(e); this.contadorDeCaracteres(e) } }

Calling one function from another:

onChange = { this.activarBotonEnviar }

and call contadorDeCaracteres from activarBotonEnviar function:

activarBotonEnviar(e){
   ...
   this.activarBotonEnviar();
}

onChange={this.myFunc}

myFunc(){
    this.activarBotonEnviar();
    this.contadorDeCaracteres();
}
发布评论

评论列表(0)

  1. 暂无评论