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

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

為什么單擊單選按鈕后按鈕啟用條件不起作用?

為什么單擊單選按鈕后按鈕啟用條件不起作用?

慕的地8271018 2023-01-06 16:23:18
當我嘗試啟用刪除按鈕時,盡管我為此添加了邏輯,但它不起作用。實際上,在添加以下刪除按鈕后,刪除按鈕始終處于啟用狀態。找不到問題。這是代碼:運動.js// initiallising statesconst [items1, setItems1] = useState({pageCount: '',field_names_state: [],toggle: false,elements: [],data_form: [],sports_id: '',buttonDisable: "0",}); const onRadioChange = (e) => {items1.sports_id = e.target.value;items1.buttonDisable="1";alert(items1.buttonDisable);};// mapping our fetched data and send them to Table_Sports.jsconst data1 = items1.elements.map((item) => (<Table_Sports key={item.sports_id} item={item} action={onRadioChange} />));<button type='button' disabled={items1.buttonDisable=="1"} onClick={(e) => handleDelete(e)}>    Delete</button>Table_Sports.js  <td>    <input      type='radio'      // defaultValue={props.item.sports_id}      defaultValue={props.}      name='sports_id'      onClick={(e) => props.action(e)}    />  </td>  <td>    <input      type='text'      defaultValue={props.item.sports_name}      name='sports_name'      contentEditable='true'    />  </td>
查看完整描述

1 回答

?
ABOUTYOU

TA貢獻1812條經驗 獲得超5個贊

要更改狀態的值,您應該調用 setItems1,將新的狀態對象作為參數傳遞,而不是直接操作它的屬性。如果您像這樣更改 onRadioChange 函數,它應該可以工作:


const onRadioChange = (e) => {

    setItems1({

        ...items1,

        sports_id: e.target.value,

        buttonDisable: "1",

    });

};


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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