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

How to lock focus in jquery

(*-*)浩
(*-*)浩Original
2019-05-30 10:46:052730browse

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)

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>

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!

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
Previous article:How jquery handles eventsNext article:How jquery handles events