Примеры для jQuery .focus()


Fire focus.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>focus demo</title>
<style>
span {
display: none;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p><input type="text"> <span>focus fire</span></p>
<p><input type="password"> <span>focus fire</span></p>
<script>
$( "input" ).focus(function() {
$( this ).next( "span" ).css( "display", "inline" ).fadeOut( 1000 );
});
</script>
</body>
</html>

Демонстрация:

To stop people from writing in text input boxes, try:

1
2
3
$( "input[type=text]" ).focus(function() {
$( this ).blur();
});

To focus on a login input box with id 'login' on page startup, try:

1
2
3
$( document ).ready(function() {
$( "#login" ).focus();
});