-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchInput.html
More file actions
156 lines (141 loc) · 2.96 KB
/
SearchInput.html
File metadata and controls
156 lines (141 loc) · 2.96 KB
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>serchInput</title>
<style>
html,
body {
font-family: 微软雅黑;
overflow: hidden;
}
.content {
width: 420px;
position: absolute;
left: 50%;
top: 40%;
margin-left: -200px;
margin-top: -40px;
text-align: center;
padding:0 10px;
}
.content>h2 {
color: #666;
letter-spacing: 2px;
}
.search-text {
display: block;
float: left;
height: 38px;
width: 309px;
font-size: 16px;
color: #777;
outline: none;
padding: 0 0 0 10px;
margin: 0;
border: 1px solid #b4b4b4;
border-right-width: 0;
letter-spacing: 1px;
}
.search-text:hover {
border: 1px solid #888;
border-right-width: 0;
}
.search-text:focus {
border: 1px solid #2DD1AF;
border-right-width: 0;
}
.search-btn {
display: block;
height: 40px;
width: 80px;
padding: 0;
float: left;
margin: 0;
border: none;
cursor: pointer;
letter-spacing: 2px;
font-size: 14px;
font-family: 微软雅黑;
background: #2DD1AF;
color: #fff;
outline: none;
-moz-border-radius: 0px 4px 4px 0px;
-webkit-border-radius: 0px 4px 4px 0px;
border-radius: 0px 4px 4px 0px;
-webkit-transition: background 0.3s ease-in-out;
-moz-transition: background 0.3s ease-in-out;
transition: background 0.3s ease-in-out;
}
.search-btn:hover {
background: #29BC95;
}
#search-suggest {
position: absolute;
left: 50%;
top: 40%;
margin-left: -190px;
margin-top: 70px;
display: none;
background: #fff;
}
#search-suggest ul {
list-style: none;
width: 318px;
border: 1px solid #b4b4b4;
padding: 0;
margin: 0;
box-shadow: 1px 2px 10px rgba(0, 0, 0, 0.15);
}
#search-suggest ul li {
padding: 3px 10px;
letter-spacing: 1px;
cursor: pointer;
font-size: 15px;
}
#search-suggest ul li:hover {
background: #eee;
}
</style>
</head>
<body>
<form class="content">
<h2>前端搜索框效果制作</h2>
<input class="search-text" id="search-text" type="text" placeholder="请输入搜索内容" maxlength="50">
<input type="button" class="search-btn" value="搜索">
</form>
<div class="suggest" id="search-suggest">
<ul>
<li>动态AJAX数据1</li>
<li>动态AJAX数据2</li>
<li>动态AJAX数据3</li>
<li>动态AJAX数据4</li>
</ul>
</div>
<script>
var oSearchText = document.getElementById('search-text');
var oSearchSuggest = document.getElementById('search-suggest');
document.addEventListener('keyup', function (e) {
e = e || event;
if(e.target.tagName.toLowerCase() == 'input') {
if (oSearchText.value.length) {
oSearchSuggest.style.display = 'block';
}
else {
oSearchSuggest.style.display = 'none';
}
}
});
document.addEventListener('click', function (e) {
e = e || event;
if (oSearchText.value.length) {
if (e.target.tagName.toLowerCase() != 'input') {
oSearchSuggest.style.display = 'none';
}else {
oSearchSuggest.style.display = 'block';
}
}
})
</script>
</body>
</html>