-
Notifications
You must be signed in to change notification settings - Fork 0
/
focus-blur.html
52 lines (52 loc) · 1.44 KB
/
focus-blur.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="js/scripts/jquery.js"></script>
<style>
.change{
outline: none;
border: 1px solid red;
background-color:#fcc;
}
.container{
width: 400px;
margin: 20px auto;
}
.container div{
margin: 20px;
}
</style>
<script>
$(function(){
$('input').focus(function(){
$(this).addClass('change')
}).blur(function(){
$(this).removeClass('change')
})
})
</script>
</head>
<body>
<form class="container">
<fieldset>
<legend>文本框获取焦点和失去焦点</legend>
<div>
<label for="username">名称:</label>
<input type="text" id="username">
</div>
<div>
<label for="password">密码:</label>
<input type="password" id="password">
</div>
<div>
<label for="msg">详细信息:</label>
<textarea id="msg"></textarea>
</div>
</fieldset>
</form>
</body>
</html>