javascript - Detect if input has focus - Stack Overflow

One of my web app's page consists of a grid and a search box. I capture the keypress event to sele

One of my web app's page consists of a grid and a search box. I capture the keypress event to select through each of the grid's rows using the space bar. However, this creates a problem for when someone wants to look up a phrase in the search box.

I know that jQuery has a .focus method to bind an event handler to an input or give focus to an element. But how do I get a boolean value to determine if the search input has focus or not?

One of my web app's page consists of a grid and a search box. I capture the keypress event to select through each of the grid's rows using the space bar. However, this creates a problem for when someone wants to look up a phrase in the search box.

I know that jQuery has a .focus method to bind an event handler to an input or give focus to an element. But how do I get a boolean value to determine if the search input has focus or not?

Share Improve this question edited Jul 27, 2012 at 18:28 Felix Kling 818k181 gold badges1.1k silver badges1.2k bronze badges asked Jul 27, 2012 at 18:26 Zishan NenoZishan Neno 2,8277 gold badges36 silver badges60 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

try this

if ($("#id").is(":focus")) {
  alert('focus');
}

you can find more info on below link :

Using jQuery to test if an input has focus

Like so?

if($('...').is(':focus')){

}

Perhaps:

$(this).is(":focus");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745103430a4611414.html

相关推荐

  • javascript - Detect if input has focus - Stack Overflow

    One of my web app's page consists of a grid and a search box. I capture the keypress event to sele

    9小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信