Using jQuery to test if an input has focus

后端 未结 15 1483
梦谈多话
梦谈多话 2020-11-22 05:42

On the front page of a site I am building, several

s use the CSS :hover pseudo-class to add a border when the mouse is over them. One of
15条回答
  •  眼角桃花
    2020-11-22 06:24

    As far as I know, you can't ask the browser if any input on the screen has focus, you have to set up some sort of focus tracking.

    I usually have a variable called "noFocus" and set it to true. Then I add a focus event to all inputs that makes noFocus false. Then I add a blur event to all inputs that set noFocus back to true.

    I have a MooTools class that handles this quite easily, I'm sure you could create a jquery plugin to do the same.

    Once that's created, you could do check noFocus before doing any border swapping.

提交回复
热议问题