Get the App
SLTechnology News&Howtos  ›  Development  › 

How does jquery determine whether or not to lose focus

Shulou Source: shulou.com Published: 2022-06-01 01:27:11 10月01日 Update

This article introduces the relevant knowledge of "how to judge whether jquery loses focus". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In jquery, the blur () and focus () methods are used to determine whether an element loses focus, which is used to trigger events when an element loses focus. The syntax is "element object .blur (function () {lose focus code;} element object .focus (function ()) {get focus code;}".

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How does jquery judge whether or not to lose focus

The blur event occurs when an element loses focus.

The blur () method triggers the blur event, or specifies the function to run when the blur event occurs.

Trigger the blur event for the selected element:

(selector) .blur ()

Add a function to the blur event:

$(selector) .blur (function)

The focus event occurs when the element gains focus.

The focus () method triggers the focus event, or specifies the function to run when the focus event occurs.

The focus event that triggers the selected element:

(selector) .focus ()

Add a function to the focus event:

$(selector) .focus (function)

Examples are as follows:

(document) .ready (function () {$("input") .blur (function () {document.getElementById ('city') [xss_clean] = "out of focus";}); $("input") .focus (function () {document.getElementById (' city') [xss_clean] = "focus";}); enter your name: determine whether the input box loses focus

Output result:

This is the end of "how to determine whether jquery loses focus". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Focus events elements functions methods code content objects more knowledge input output run practical learned and then name dilemma reality situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Xiaomi Docker Apple MariaDB