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


Show the event object for the keyup handler (using a simple $.print plugin) when a key is released in the input.

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>keyup demo</title>
<style>
fieldset {
margin-bottom: 1em;
}
input {
display: block;
margin-bottom: .25em;
}
#print-output {
width: 100%;
}
.print-output-line {
white-space: pre;
padding: 5px;
font-family: monaco, monospace;
font-size: .7em;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form>
<fieldset>
<label for="target">Type Something:</label>
<input id="target" type="text">
</fieldset>
</form>
<button id="other">
Trigger the handler
</button>
<script type="text/javascript" src="/resources/events.js"></script>
<script>
var xTriggered = 0;
$( "#target" ).keyup(function( event ) {
xTriggered++;
var msg = "Handler for .keyup() called " + xTriggered + " time(s).";
$.print( msg, "html" );
$.print( event );
}).keydown(function( event ) {
if ( event.which == 13 ) {
event.preventDefault();
}
});
$( "#other").click(function() {
$( "#target" ).keyup();
});
</script>
</body>
</html>

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