栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在ReactJS中获取表单数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在ReactJS中获取表单数据

使用

change
输入上的事件来更新组件的状态并在
handleLogin
以下位置访问它:

handleEmailChange: function(e) {   this.setState({email: e.target.value});},handlePasswordChange: function(e) {   this.setState({password: e.target.value});},render : function() {      return (        <form>          <input type="text" name="email" placeholder="Email" value={this.state.email} onChange={this.handleEmailChange} />          <input type="password" name="password" placeholder="Password" value={this.state.password} onChange={this.handlePasswordChange}/>          <button type="button" onClick={this.handleLogin}>Login</button>        </form>);},handleLogin: function() {    console.log("EMail: " + this.state.email);    console.log("Password: " + this.state.password);}

以前,您还可以使用React的双向数据绑定帮助器mixin来实现相同的功能,但是现在不建议使用它来设置值和更改处理程序(如上所述):

var ExampleForm = React.createClass({  mixins: [React.addons.linkedStateMixin],  getInitialState: function() {    return {email: '', password: ''};  },  handleLogin: function() {    console.log("EMail: " + this.state.email);    console.log("Password: " + this.state.password);  },  render: function() {    return (      <form>        <input type="text" valuelink={this.linkState('email')} />        <input type="password" valuelink={this.linkState('password')} />        <button type="button" onClick={this.handleLogin}>Login</button>      </form>    );  }});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/464952.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号