<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script src="../js/react.development.js"></script>
<script src="../js/react-dom.development.js"></script>
<script src="../js/babel.min.js"></script>
<script src="../js/prop-types.js"></script>
<script type="text/babel">
class Input extends React.Component{
submitHandle=(e)=>{
const {username,password}=this
e.preventDefault()
alert("我的名字"+username.value+"我的密码"+password.value)
}
render(){
return (
<form action="" onSubmit={this.submitHandle}>
用户名:<input type="text" placeholder="请输入用户名" name="name" ref={c=>this.username=c}/>
密码:<input type="password" placeholder="请输入密码" name="password" ref={c=>this.password=c} />
<button >登录</button>
</form>
)
}
}
ReactDOM.render(<Input/>,document.getElementById("app"))
</script>
</body>
</html>
页面中输入类的dom现用现取就是非控类型的组件