简体   繁体   English

如何向 React JS 中动态创建的元素添加类?

[英]How to add classes to dynamically created elements in React JS?

 {temp_array_beg.map((el,index) => ( <div key={index} className="subRenderButton"> <input type="button" value={el.i} className="paginationBtn" onClick= {this.handlePaginationClick.bind(this)} /> </div> ))}

Ihave tried Conditional Rendering of class but then all the rendered divs got the active class我试过 class 的条件渲染,但随后所有渲染的 div 都激活了 class

 {temp_array.map((btn,index) => ( <div key={index} className="subRenderButton"> <input type="button"value={btn.i} className={["paginationBtn",buttonNumber == btn.i? "active":""].join(' ')} onClick={this.handlePaginationClick.bind(this)} /> </div> ))}

I have managed to solve the problem Thanks!我已经设法解决了问题谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM