I have a standard HTML input that I want to run JavaScript code when it loses focus. Sadly my Google searches did not reveal how to do this.
我有一个标准的HTML输入,当它失去焦点时,我想要运行JavaScript代码。遗憾的是,我的谷歌搜索并没有揭示如何做到这一点。
To make it clear, I'm looking for a way to do this:
为了说明这一点,我正在寻找一种方法:
<input type="text" name="name" value="value" onlosefocus="alert(1);"/>
5 个解决方案
#1
248
How about onblur event :
onblur事件:
<input type="text" name="name" value="value" onblur="alert(1);"/>
#2
61
onblur
is the opposite of onfocus
.
onblur和onfocus相反。
#3
36
You want to use the onblur event.
你想要使用onblur事件。
<input type="text" name="name" value="value" onblur="alert(1);"/>
#5
0
From w3schools.com: Made compatible with Firefox Sept, 2016
来自w3schools.com:与火狐兼容,2016年9月
<input type="text" onfocusout="myFunction()">
#1
248
How about onblur event :
onblur事件:
<input type="text" name="name" value="value" onblur="alert(1);"/>
#2
61
onblur
is the opposite of onfocus
.
onblur和onfocus相反。
#3
36
You want to use the onblur event.
你想要使用onblur事件。
<input type="text" name="name" value="value" onblur="alert(1);"/>
#4
#5
0
From w3schools.com: Made compatible with Firefox Sept, 2016
来自w3schools.com:与火狐兼容,2016年9月
<input type="text" onfocusout="myFunction()">