import React ,{useState}from 'react';import './App.css';function App() { const password =[2,2,3]; const [digits ,setDigits]=useState([0,0,0]); const [isUnlocked,setIsUnlocked]=useState(false); let setDigitAtIndex=(digit,idx)=>{ setDigits((currentDigits)=> [ ...currentDigits.slice(0, idx), digit, ...currentDigits.slice(idx + 1) ] ); }; let checkPassword=() =>{ for (let i=0;i<password.length;i++){ if(password[i]===digits[i]){ return; } } setIsUnlocked(true); } return ( <section> <h1>Passo</h1> <div style={{display:'flex'}}> <input type="number" value={digits[0]} onChange={(event) => setDigitAtIndex(parseInt(event.target.value),0)}/> <input type="number" value={digits[1]} onChange={(event)=>setDigitAtIndex(parseInt(event.target.value),1)}/> <input type="number" value={ digits[2]} onChange={(event)=>setDigitAtIndex(parseInt(event.target.value),2)}/> </div> <button onClick={()=>checkPassword()}>Press Me</button> { isUnlocked && <p>Unlocked</p>} </section> );}export default App;在反應(yīng)中運(yùn)行此應(yīng)用程序后,當(dāng)我單擊帶有 0 0 0 的按我按鈕時(shí),它顯示已解鎖,但在輸入 2 2 3 后它不起作用,但在輸入 223 后應(yīng)該可以工作需要幫助嗎?以及任何正在學(xué)習(xí)反應(yīng)的人那些可以回答這個(gè)問題
密碼檢查器顯示解鎖 (0,0,0) 但未解鎖給定數(shù)字(密碼)
繁星點(diǎn)點(diǎn)滴滴
2023-11-13 10:42:58