Home > Web Front-end > JS Tutorial > How to lock focus in jquery

How to lock focus in jquery

(*-*)浩
Release: 2019-05-30 10:46:05
Original
2752 people have browsed it

To obtain focus, you need to use jQuery's focus method.

How to lock focus in jquery

Definition and Usage

The focus event occurs when an element gains focus.

When an element is selected by mouse click or positioned by tab key, the element will gain focus.

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

Bind a function to the focus event

Syntax

$(selector).focus(function)
Copy after login

function: Optional. Specifies the function to be run when the focus event occurs.

Example:

Lock focus

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("input").focus(function(){
    $("input").css("background-color","#FFFFCC");
  });
 
});
</script>
</head>
<body>
Enter your name: <input type="text" />
<p>请在上面的输入域中点击,使其获得焦点,然后就锁定焦点了。</p>
</body>
</html>
Copy after login

The above is the detailed content of How to lock focus in jquery. 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