检测Javascript事件类型 [英] Detect Javascript event type
本文介绍了检测Javascript事件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的javascript中有一个OPEN函数,当用户模糊(失去对输入字段的关注)或按Enter键时,就会调用
There is a function OPEN in my javascript which is called when the user either blur (lose focus on the input field) or hit Enter.
然后在OPEN()中,取决于它是由模糊还是按键触发的,它会导致两个其他函数.
Then within OPEN(), depending on whether it was triggered by blur or keypress, it leads to two different other functions.
对于Keypress,我是这样做的.
For the Keypress, I did it like this.
if (e.keyCode==13) ENTER_FX();
您如何针对BLUR做到这一点
How do you do this for BLUR
谢谢
更新:
我发现它应该是e.type =="focusout"
I found that it should be e.type=="focusout"
聚焦是正确的词而不是模糊的词吗?
So is focusout the right word instead of blur?
推荐答案
WORKING JSFIDDLE EXAMPLE
e.type
为您提供此信息
function OPEN(e) {
if (e.type !== "blur") {
if (e.keyCode === 13) {
ENTER_FX();
}
}
else {
ENTER_FX();
}
}
这篇关于检测Javascript事件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文