我对JS和Reactjs很陌生,并且已经尝试了几天来找到一个简单的解决方案。
我有一个表格,并希望根据数量更新金额值,因为这是传递到我的支付网关(payfast(的内容。任何帮助将不胜感激!
<input type="hidden" name="amount" value="840" />
<input type="numeric" id="qty" name="Quantity" placeholder ="Qty" />
你可以
试试这个...
import React, { PureComponent /*, PropTypes*/ } from 'react'
export default class TestComponent extends PureComponent {
static propTypes = {
// PropTypes go here
}
constructor(props) {
super(props)
this.state = {
amountVal: 894
}
this.otherFunction = this.otherFunction.bind(this)
}
handleChange(e) {
this.setState({amountVal: e.target.value})
}
otherFunction() {
// you can use amountVal from this.state.amountVal inside this function
console.log(this.state.amountVal)
}
render() {
return (
<div>
<h1>Test</h1>
<input type="hidden" name="amount" value={this.state.amountVal}/>
<input type="numberic" id="qty" onChange={this.handleChange.bind(this)} name="Quantity" placeholder ="Qty"/>
</div>
)
}
}