-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.html
180 lines (165 loc) · 4.46 KB
/
test.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>百度</title>
<style>
* {
margin: 0;
padding: 0;
}
#rootbody {
margin: 0 auto;
width: 100%;
text-align: center;
}
#logo {
margin-top: 60px;
}
#inputarea {
position: relative;
width: 580px;
height: 38px;
margin: 0 auto;
margin-top: 48px;
}
#edit {
height: 38px;
border: 1px solid #3385ff;
box-sizing: border-box;
}
#edit:hover {
border: 1px solid #317ef3;
}
#inputtext {
border: 0; /* 所有的表单边框为0 */
outline: none; /*去除选中样式*/
background-color: white;
height: 36px;
float: left;
width: 470px;
box-sizing: border-box;
padding-left: 10px;
vertical-align: middle;
font-size: 17px;
}
#baidu {
width: 90px;
background: #3385ff;
height: 36px;
color: white;
line-height: 36px;
box-sizing: border-box;
float: right;
vertical-align: middle;
cursor: pointer;
}
#baidu :hover{
background: #317ef3;
}
.list {
position: absolute;
top: 38px;
left: 0px;
width: 487px;
border: 1px solid #a6a6a6;
border-top: none;
display: none;
}
.ulstyle {
list-style: none;
text-align: left;
}
.listyle {
text-align: left;
color: #4986f7;
font-size: 15px;
line-height: 35px;
padding-left: 10px;
/*强制一行*/
white-space: nowrap;
/*超出隐藏*/
overflow: hidden;
/*超出 部分省略号*/
text-overflow: ellipsis;
cursor: pointer;
vertical-align: middle;
}
li span {
font-weight: 800;
color: #aa9301;
font-size: 18px;
}
</style>
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?41cc1334afa3eded19a39d7628ed3a01";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<div id="rootbody">
<img id="logo" width="279" height="128" src="http://www.baidu.com/img/bd_logo1.png">
<div id="inputarea">
<div id="edit">
<input id="inputtext" type="text" placeholder="请输入"/>
<p id="baidu">模糊查找</p>
</div>
<div id="list" class="list">
<ul class="ulstyle">
<li class="listyle"><span>ee</span>reqwrew</li>
<li class="listyle">456</li>
<li class="listyle">789</li>
</ul>
</div>
</div>
</div>
<script>
var inputtext = document.getElementById("inputtext")
var list = document.getElementById("list")
inputtext.oninput = function () {
var ul = document.createElement('ul')
ul.className = 'ulstyle'
var linecout = inputtext.value.length;
if (linecout === 0) {
list.style.display = 'none'
return;
}
list.style.display = 'block'
if (linecout > 10) {
linecout = 10;
}
var height = 0;
for (var i = 0; i < linecout; i++) {
var li = document.createElement('li')
li.className = 'listyle'
li.innerHTML = "<span>" + inputtext.value + "</span>测试"+i
ul.appendChild(li)
height = height + 36
li.onmouseover=overMouse
li.onmouseout=outMouse
li.onclick=clickliListItem
}
list.style.height = height + "px";
if (list.children.length > 0) {
list.replaceChild(ul, list.children[0])
} else {
list.appendChild(ul)
}
}
function clickliListItem() {
inputtext.value= this.textContent
}
function overMouse() {
this.style.background = '#eaeaea'
}
function outMouse() {
this.style.background = 'white'
}
</script>
</body>
</html>