Using jQuery to test if an input has focus

后端 未结 15 1442
梦谈多话
梦谈多话 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

    What I wound up doing is creating an arbitrary class called .elementhasfocus which is added and removed within the jQuery focus() function. When the hover() function runs on mouse out, it checks for .elementhasfocus:

    if(!$("#quotebox").is(".boxhasfocus")) $(this).removeClass("box_border");
    

    So if it doesn't have that class (read: no elements within the div have focus) the border is removed. Otherwise, nothing happens.

提交回复
热议问题