JavaScript - OffFocus事件? [英] JavaScript - OffFocus event?

查看:145
本文介绍了JavaScript - OffFocus事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是显示一个文本颜色为黑色的输入字段。

然后当人点击输入栏(onfocus)我想改变文字颜色为 red



然后,当那个人在输入框外面点击(不再焦点),我想把文本颜色改回黑色



我知道如何使用以下方法处理JavaScript onfocus事件:

 < input ctype =textonfocus = this.style.color = '红色'; /> 

但是,如何处理关闭焦点以将文字颜色改回黑色



预先感谢 尝试使用 onblur ,当元素失去焦点时调用它。

What I want to do is display an input field with the text color black.

Then when the person clicks inside the input field (onfocus) I want to change the text color to red.

Then, when the person click outside of the input fied (no longer focus), I want to change the text color back to black.

I know how to handle the JavaScript onfocus Event using the following:

<input ctype="text" onfocus="this.style.color='red';" />

But how do I handle the "off focus" to change the text color back to black?

Thanks in advance

解决方案

try using onblur, it is called when an element loses focus.

这篇关于JavaScript - OffFocus事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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