<small id='SfL0v'></small><noframes id='SfL0v'>

  • <i id='SfL0v'><tr id='SfL0v'><dt id='SfL0v'><q id='SfL0v'><span id='SfL0v'><b id='SfL0v'><form id='SfL0v'><ins id='SfL0v'></ins><ul id='SfL0v'></ul><sub id='SfL0v'></sub></form><legend id='SfL0v'></legend><bdo id='SfL0v'><pre id='SfL0v'><center id='SfL0v'></center></pre></bdo></b><th id='SfL0v'></th></span></q></dt></tr></i><div id='SfL0v'><tfoot id='SfL0v'></tfoot><dl id='SfL0v'><fieldset id='SfL0v'></fieldset></dl></div>
      • <bdo id='SfL0v'></bdo><ul id='SfL0v'></ul>

      1. <legend id='SfL0v'><style id='SfL0v'><dir id='SfL0v'><q id='SfL0v'></q></dir></style></legend>

        <tfoot id='SfL0v'></tfoot>

        如何使用react js在另一个页面显示html表单提交的信息?

        时间:2023-09-05
              <legend id='Tccgy'><style id='Tccgy'><dir id='Tccgy'><q id='Tccgy'></q></dir></style></legend>
                <tbody id='Tccgy'></tbody>

              • <bdo id='Tccgy'></bdo><ul id='Tccgy'></ul>

                1. <tfoot id='Tccgy'></tfoot>

                  <small id='Tccgy'></small><noframes id='Tccgy'>

                  <i id='Tccgy'><tr id='Tccgy'><dt id='Tccgy'><q id='Tccgy'><span id='Tccgy'><b id='Tccgy'><form id='Tccgy'><ins id='Tccgy'></ins><ul id='Tccgy'></ul><sub id='Tccgy'></sub></form><legend id='Tccgy'></legend><bdo id='Tccgy'><pre id='Tccgy'><center id='Tccgy'></center></pre></bdo></b><th id='Tccgy'></th></span></q></dt></tr></i><div id='Tccgy'><tfoot id='Tccgy'></tfoot><dl id='Tccgy'><fieldset id='Tccgy'></fieldset></dl></div>
                  本文介绍了如何使用react js在另一个页面显示html表单提交的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想使用 react js 在另一个页面上显示填写在 html 表单中的所有详细信息.我创建了作为登录页面的 html 表单.点击提交后,所有信息应显示在另一个页面上.

                  用于创建 html 表单的 form.js 页面

                  import React, { component } from 'react';var details = () =>{返回(

                  <表格>名称: {" "}<input type="text" placeholder="输入姓名"/><br/>联系方式.: {" "}<input type="number" placeholder="输入联系电话"/><br/><输入类型="提交" 值="提交"/></表格></div>);}导出默认详细信息;

                  我的 app.js 页面

                  从'react'导入反应;从'./logo.svg'导入标志;导入'./App.css';从 './form/form' 导入详细信息;函数应用程序(){返回 (<div className="App"><header className="App-header"><详情/></标题></div>);}导出默认应用程序;

                  解决方案

                  首先,我们要在app上创建一个可以接收数据的函数,然后将其作为prop发送给组件:

                  import React from 'react';从 './form' 导入详细信息;函数应用程序(){const getFormData = function (name, number) {console.log('姓名:',姓名,'编号:',编号)}返回 (<div className="App"><header className="App-header"><详情 sendFormData={getFormData}/></标题></div>);}导出默认应用

                  然后,在组件内部,您要设置每个输入以在它们更改时更新它们的状态.单击提交时,会将状态传递给应用组件的 getFormData 函数.

                  import React, { useState } from 'react';const 详细信息 = (props) =>{const [userName, setName] = useState('');const [userNumber, setNumber] = useState('');常量句柄提交 = () =>{props.sendFormData(userName, userNumber)}返回 (

                  名称: {" "}<输入类型=文本"占位符=输入名称"onChange={事件=>setName(event.target.value)}/>

                  I want to show all the details filled in the html form on another page using react js. I have created the html form which is the landing page. And after clicking on submit all the information should be displayed on another page.

                  My form.js page for creating the html form

                  import React, { component } from 'react';
                  
                  var details = () => {
                      return(
                          <div>
                              <form>
                                  Name: {" "}
                                  <input type="text" placeholder="Enter name" /><br />
                                  Contact No.: {" "}
                                  <input type="number" placeholder="Enter contact number" />
                                  <br />
                                  <input type="submit" value="submit"/>
                              </form>
                          </div>
                      );
                  }
                  
                  
                  export default details;
                  

                  My app.js page

                  import React from 'react';
                  import logo from './logo.svg';
                  import './App.css';
                  import Details from './form/form';
                  function App() {
                    return (
                      <div className="App">
                        <header className="App-header">
                          <Details />
                        </header>
                      </div>
                    );
                  }
                  
                  export default App;
                  
                  

                  解决方案

                  First, on the app we want to create a function that can receive the data, then send it to the component as a prop:

                  import React from 'react';
                  import Details from './form';
                  function App() {
                  	const getFormData = function (name, number) {
                  		console.log('Name: ', name, 'Number: ', number)
                  	}
                  	return (
                  		<div className="App">
                  			<header className="App-header">
                  				<Details sendFormData={getFormData} />
                  			</header>
                  		</div>
                  	);
                  }
                  
                  export default App

                  Then, inside the component you want to set each input to update their state as they change. When you click submit, you pass the state to the up to the app components getFormData function.

                  import React, { useState } from 'react';
                  
                  const Details = (props) => {
                  	const [userName, setName] = useState('');
                  	const [userNumber, setNumber] = useState('');
                  	const handleSubmit = () => {
                  		props.sendFormData(userName, userNumber)
                  	}
                  
                  	return (
                  		<div>
                  			Name: {" "}
                  			<input type="text" placeholder="Enter name"
                  				onChange={event => setName(event.target.value)} /><br />
                  			Contact No.: {" "}
                  			<input type="number" placeholder="Enter contact number"
                  				onChange={event => setNumber(event.target.value)} />
                  			<br />
                  			<button onClick={() => handleSubmit()} >Submit</button>
                  		</div>
                  	);
                  }
                  
                  export default Details;

                  这篇关于如何使用react js在另一个页面显示html表单提交的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  • <tfoot id='lmVGd'></tfoot>
                  • <small id='lmVGd'></small><noframes id='lmVGd'>

                    • <bdo id='lmVGd'></bdo><ul id='lmVGd'></ul>

                      <i id='lmVGd'><tr id='lmVGd'><dt id='lmVGd'><q id='lmVGd'><span id='lmVGd'><b id='lmVGd'><form id='lmVGd'><ins id='lmVGd'></ins><ul id='lmVGd'></ul><sub id='lmVGd'></sub></form><legend id='lmVGd'></legend><bdo id='lmVGd'><pre id='lmVGd'><center id='lmVGd'></center></pre></bdo></b><th id='lmVGd'></th></span></q></dt></tr></i><div id='lmVGd'><tfoot id='lmVGd'></tfoot><dl id='lmVGd'><fieldset id='lmVGd'></fieldset></dl></div>

                      1. <legend id='lmVGd'><style id='lmVGd'><dir id='lmVGd'><q id='lmVGd'></q></dir></style></legend>
                          <tbody id='lmVGd'></tbody>