反应如何在输入模糊时触发表单提交? [英] React how to trigger form submit on input blur?

查看:50
本文介绍了反应如何在输入模糊时触发表单提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用HTML5 < input type ="email"/> 验证检查.

I'm trying to make use of the HTML5 <input type="email" /> validation check.

我可以很好地做到这一点:

I can get it working fine doing this:

<form>
  <input type="email" />
  <input type="submit" />
</form>

这将使验证在单击sumbit按钮时起作用.但是,我想在 email 字段模糊时触发表单提交.

This gets the validation to work on clicking the sumbit button. However I'd like to trigger the form to submit upon having my email field blur.

如何在没有提交按钮 onBlur 的情况下触发表单?

How do I trigger the form without a submit button onBlur?

赞:

<form>
  <input type="email" onBlur={/* trigger form submission */} />
</form>

或者,是否有更好的方法可以在输入模糊时执行HTML5电子邮件验证检查?

Alternatively, is there a better approach to performaning the HTML5 email validation check upon input blur?

推荐答案

在表单上放置一个 ref 属性,然后调用Submit函数:

Put a ref attribute on your form and call the submit function:

<form ref="myForm">
  <input type="email" onBlur={this.submitForm.bind(this)} />
</form>

添加功能

submitForm(){
  this.refs['myForm'].submit()
}

这篇关于反应如何在输入模糊时触发表单提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆