Home  >  Article  >  Web Front-end  >  Whether jquery gets focus

Whether jquery gets focus

coldplay.xixi
coldplay.xixiOriginal
2020-11-27 14:25:162149browse

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");  
}

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!

Statement:
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