开发者

Detect Javascript event type

开发者 https://www.devze.com 2023-04-03 10:40 出处:网络
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.

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.

Then within OPEN(), depending on whether it was triggered by blur or keypress, it leads to two different other functions.

For the Keypress, I did it like this.

开发者_StackOverflow
        if (e.keyCode==13) ENTER_FX();

How do you do this for BLUR

Thank you

UPDATE:

I found that it should be e.type=="focusout"

So is focusout the right word instead of blur?


WORKING JSFIDDLE EXAMPLE

e.type

gives you this information

function OPEN(e) {
    if (e.type !== "blur") {
        if (e.keyCode === 13) {
            ENTER_FX();
        }
    }
    else {
        ENTER_FX();
    }
}


e.type should probably say 'blur' in that case.


Try if(e.type == "blur") /*code here*/

event.type reference

0

精彩评论

暂无评论...
验证码 换一张
取 消