最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Detect Javascript event type - Stack Overflow

programmeradmin1浏览0评论

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.

        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?

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.

        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?

Share Improve this question edited Sep 8, 2011 at 21:54 jondavidjohn 62.4k21 gold badges120 silver badges159 bronze badges asked Sep 8, 2011 at 21:32 William ShamWilliam Sham 13.2k11 gold badges51 silver badges67 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 12

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)

  1. 暂无评论