亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 React JS 中形成加載時提交?

如何在 React JS 中形成加載時提交?

子衿沉夜 2023-05-19 18:16:47
在 ReactJS 中加載頁面時如何提交form?<form id="redirectForm" method="post" action="https://test.cashfree.com/billpay/checkout/post/submit">  <input type="text" name="appId" value={this.state.appId}/>  <input type="text" name="orderId" value={this.state.orderId}/>  <input type="text" name="orderAmount" value={this.state.orderAmount}/>  <input type="text" name="orderCurrency" value={this.state.orderCurrency}/>  <input type="text" name="orderNote" value={this.state.orderNote} />  <input type="text" name="customerName" value={this.state.customerName}/>  <input type="text" name="customerEmail" value={this.state.customerEmail} />  <input type="text" name="customerPhone" value={this.state.customerPhone} />  <input type="text" name="returnUrl" value={this.state.returnUrl} />  <input type="text" name="notifyUrl" value={this.state.notifyUrl} />  <input type="text" name="signature" value={this.state.signature}/>  <button type="submit">Pay</button></form>Java腳本:<script>document.getElementById("redirectForm").submit();</script>
查看完整描述

1 回答

?
互換的青春

TA貢獻1797條經驗 獲得超6個贊

你實際上可以為表單創建一個ref,如果組件是類組件,你可以用來componentDidMount提交表單,或者如果是功能組件,你可以通過useEffect


<form ref={item => this.form = item} id="redirectForm" method="post" action="https://test.cashfree.com/billpay/checkout/post/submit">?

.....

</form>

在您的 React 組件中,您可以使用以下方法創建 ref:


class SampleClass extends React.Component {

? ?constructor() {

? ? ?this.form = null

? ?}


? ?componentDidMount() {

? ? this.form.submit();

? ?}

}

您可以使用 useRef 和 useEffect 將類似的邏輯應用于功能組件。

查看完整回答
反對 回復 2023-05-19
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號