我对JS和Reactjs很陌生,并且几天来一直试图找到一个简单的解决方案。
我有一个表单,并希望根据数量更新金额值,因为这是传递给我的支付网关(payfast)的内容。任何帮助都会受到大力赞赏!
<input type="hidden" name="amount" value="840" />
<input type="numeric" id="qty" name="Quantity" placeholder ="Qty" />
答案 0 :(得分:1)
你可以试试这个......
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>
)
}
}