【发布时间】:2021-02-02 03:45:29
【问题描述】:
我正在使用 React Js 做一个简单的联系表单,我已经使用 react bootstrap 创建了组件,但是当我尝试输入输入字段时,我根本没有改变。
import React, {useState} from 'react';
import { Container, Row, Col,Form , Button} from "react-bootstrap";
import Particle from "./Particle";
import "../style.css";
import "bootstrap/dist/css/bootstrap.min.css";
function ContactMe(){
const [name, setname] = useState("");
function handelChange(e){
const newName = e.target.value;
setname(newName);
console.log(newName);
}
return (
<Container fluid className="about-section">
<Particle />
<Container>
<h1>Contact Me form </h1>
<Container className="d-flex flex-column">
<Form>
<label>Name</label>
<Form.Control type="text" placeholder="Enter your name" onChange={handelChange} value={name}/>
<label>Email</label>
<Form.Control type="email" placeholder="Enter your Email" />
<label>Message</label>
<Form.Control as="textarea" type="text" placeholder="Enter your message" />
<Button variant="outline-danger mt-5 ">Danger</Button>
</Form>
</Container>
</Container>
</Container>
);
}
导出默认的 ContactMe;`
我已尝试删除value={name},但效果不佳
【问题讨论】:
-
我曾尝试使用
<input></input>和,但效果不佳 -
如果您删除
onChange和value属性,您可以在文本字段中输入任何内容还是保持空白?
标签: javascript reactjs forms input react-bootstrap