DEV Community

打coding的奥特曼
打coding的奥特曼

Posted on

react在非受控下读取form表单

 const Form = ()=>{ const handleSubmit = (e)=>{ e.preventDefault(); const formData = new FormData(e.target) const data = Object.fromEntries(formData.entries()) console.log(data ) } return ( <form onSubmit={handleSubmit} > <input type="text" name='username' placeholder='username'/> <input type="email" name='email' placeholder='email'/> <input type="password" name='password' placeholder='password' /> <input type="password" placeholder='confirm password' /> <button>submit</button> </form> ) } export default Form 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)