离开输入字段后调用函数 [英] Call a function after leaving input field

查看:74
本文介绍了离开输入字段后调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在联系表单上,我有几个输入字段。其中一个字段是电子邮件地址字段:

On a contact form, I have several input fields. One of those fields, is an email address field:

<input type='text' name='input_email' onChange={this.validateEmail}/>

现在,我已将电子邮件验证功能设置为onChange属性。因此,当用户在电子邮件字段中输入字符时,整个时间都会显示错误消息。

Right now, I have the email validation function set to the onChange attribute. Thus, while the user is entering characters into the email field, an error message appears the whole time.

我想更改此信息,以便 this.validateEmail 仅在用户离开该特定输入字段时被调用一次。我怎么做到这一点?

I want to change this, so that this.validateEmail only gets called once when the user leaves that specific input field. How would I accomplish this?

我找不到任何可以解决此问题的默认对象事件。

I can't find any default object events that would solve this issue.

FYI,使用ReactJS

FYI, using ReactJS

推荐答案

您可以使用 onblur() onfocusout在()。一旦你点击该文本字段,它就会调用函数。

You can use onblur() or onfocusout(). It will call function once you click out of that text field.

示例:

function myFunction() {
    var x = document.getElementById("sometext");
    x.value = x.value.toUpperCase();
}

<input type="text" id="sometext" onfocusout="myFunction()">

这篇关于离开输入字段后调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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