-
Notifications
You must be signed in to change notification settings - Fork 35
/
form.events.html
160 lines (150 loc) · 6.58 KB
/
form.events.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>События формы</title>
<link rel="profile" href="https://gmpg.org/xfn/11"/>
<link rel="shortcut icon" href="https://anton.shevchuk.name/favicon.ico"/>
<link rel="stylesheet" href="css/styles.css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
let sel = function (ev) {
/*if (ev.target != undefined) {
$('#element').html(ev.target.id);
}*/
let el = '#' + ev.type
let counter = $(el).find('span').html()
if (counter === '') counter = 0
$(el)
.find('span')
.html(++counter)
.css({ background: '#fe3456', color: '#ffffff' })
}
$(function (ev) {
$('#first')
.blur(sel)
.focus(sel)
.focusin(sel)
.focusout(sel)
$('#last')
.keydown(sel)
.keypress(sel)
.keyup(sel)
$('textarea')
.change(sel)
.select(sel)
$('select').change(sel)
$('input[name=checkbox]').change(sel)
$('input[name=radio]').change(sel)
$('form')
.submit(sel)
.submit(() => false)
sel(ev)
})
</script>
</head>
<body>
<header>
<h1>События формы</h1>
<h2>Фокус, редактирование, отправка и прочие.</h2>
</header>
<main>
<article>
<form>
<fieldset>
<label for="first"></label><input type="text" id="first" name="first" placeholder="First name"/>
<label for="last"></label><input type="text" id="last" name="last" placeholder="Last name"/>
<label>
<textarea name="editor" cols="64" rows="16">Lorem ipsum dolor sit amet, consectetur adipiscing lit. Phasellus rutrum,
lectus eu varius consectetur, libero velit hendrerit augue, ut posuere enim neque
in libero. Donec eget sagittis nibh. Suspendisse sed tincidunt urna. Cras quis
euismod neque. Maecenas auctor ultricies posuere. Pellentesque luctus pulvinar dui
eget semper. Donec sodales odio eu sapien varius luctus. Donec dictum feugiat diam
at malesuada. Sed nec massa in augue condimentum faucibus quis ut diam. Quisque
nisl sem, semper nec vulputate vel, mattis sit amet justo. Aliquam purus felis,
tempor at scelerisque quis, tincidunt in neque. Etiam ut risus diam. Pellentesque
fermentum risus id elit feugiat cursus. Ut fringilla dictum diam, sed iaculis
lorem pulvinar ut. Cras vel elit id velit commodo viverra sit amet vel orci.</textarea>
</label>
<label for="options">Choose option: </label>
<select id="options" name="select">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
<hr/>
<label><input type="checkbox" name="checkbox" value="1"/> Checkbox</label><br/>
<hr/>
<label><input type="radio" name="radio" value="chosen 1"/> Choose 1</label><br/>
<label><input type="radio" name="radio" value="chosen 2"/> Choose 2</label><br/>
<label><input type="radio" name="radio" value="chosen 3"/> Choose 3</label><br/>
<hr/>
<button type="submit">Send Form</button>
</fieldset>
</form>
</article>
</main>
<footer>
© <a href="https://anton.shevchuk.name/jquery-book/">jQuery for beginners</a>
</footer>
<aside>
<nav>
<a href="form.basic.html" title="go prev" rel="prev">Prev</a>
<a href="index.html#80" title="back to Index" rel="index">Index</a>
<a href="#" title="reload" onclick="window.location.reload();return false">Reload</a>
<a href="form.methods.html" title="go next" rel="next">Next</a>
</nav>
<hr/>
<div>
<code><em>// обработчики событий для first</em>
$(<span>'#first'</span>)
.blur(<span>'counter'</span>)
.focus(<span>'counter'</span>)
.focusin(<span>'counter'</span>)
.focusout(<span>'counter'</span>)</code>
<code><em>// обработчики событий для last</em>
$(<span>'#last'</span>)
.keydown(<span>'counter'</span>)
.keypress(<span>'counter'</span>)
.keyup(<span>'counter'</span>)</code>
<code><em>// обработчики для textarea</em>
$(<span>'textarea'</span>)
.change(<span>'counter'</span>)
.select(<span>'counter'</span>)</code>
<code><em>// обработчик для select</em>
$(<span>'select'</span>)
.change(<span>'counter'</span>)</code>
<code><em>// обработчик для checkbox</em>
$(<span>'input[name=checkbox]'</span>)
.change(<span>'counter'</span>)</code>
<code><em>// обработчик для radio buttons</em>
$(<span>'input[name=radio]'</span>)
.change(<span>'counter'</span>)</code>
<code><em>// обработчик для form</em>
$(<span>'form'</span>)
.submit(<span>'counter'</span>)</code>
</div>
</aside>
<aside id="output">
<h4>Events:</h4>
<hr/>
<ul class="events">
<li id="change"><span>0</span><strong>change</strong> - изменение элемента</li>
<li id="focus"><span>0</span><strong>focus</strong> - фокус на элементе</li>
<li id="blur"><span>0</span><strong>blur</strong> - фокус ушел с элемента</li>
<li id="focusin"><span>0</span><strong>focusin</strong> - фокус на элементе, событие предка</li>
<li id="focusout"><span>0</span><strong>focusout</strong> - фокус ушел с элемента, событие предка</li>
<li id="keydown"><span>0</span><strong>keydown</strong> - нажатие клавиши на клавиатуре</li>
<li id="keypress"><span>0</span><strong>keypress</strong> - нажатие клавиши на клавиатуре
keydown+keyup
</li>
<li id="keyup"><span>0</span><strong>keyup</strong> - отжатие клавиши на клавиатуре</li>
<li id="select"><span>0</span><strong>select</strong> - выбор текста - актуален только для
input[type=text] и textarea
</li>
<li id="submit"><span>0</span><strong>submit</strong> - отправка формы</li>
</ul>
</aside>
</body>
</html>