Home > Web Front-end > JS Tutorial > Whether jquery gets focus

Whether jquery gets focus

coldplay.xixi
Release: 2020-12-22 17:04:41
Original
2194 people have browsed it

Jquery method of obtaining focus: Determine whether the object obtains focus by judging whether [$(object).is(":focus")] is equal to true, where the [:focus] selector is used to select the object that obtains focus. Element, the [is()] method is used to check whether the selected element matches the selector.

Whether jquery gets focus

The operating environment of this tutorial: Windows 7 system, jquery version 1.10.2. This method is suitable for all brands of computers.

How jquery gets focus:

In jquery, you can judge whether $(object).is(":focus") is equal to true to determine whether the object has focus.

When the object has focus, $(object).is(":focus") will return true, otherwise it will return false.

Example:

var isFocus=$("#tRow").is(":focus");  
if(true==isFocus){  
    alert("focus");  
}else{  
    alert("blur");  
}
Copy after login

Description:

  • is() method is used to check whether the selected element matches the selector.

  • :focus The selector is used to select the element that receives focus.

Tip: Elements that receive keyboard events or other user input allow the :focus selector.

Related free learning recommendations: javascript (video)

The above is the detailed content of Whether jquery gets focus. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template