-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSS Filter.html
68 lines (68 loc) · 2.52 KB
/
CSS Filter.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CSS Filter</title>
<style>
body {
display: flex;
justify-content: center;
align-items: flex-start;
}
ul {
padding: 0;
list-style: none;
border-bottom: 1px solid gray;
}
li {
border: 1px solid gray;
border-bottom: 0;
}
</style>
</head>
<body>
<div>
<input type="text" placeholder="输入城市名称" id="inputEle" />
<ul>
<li data-search="重庆市chongqing">重庆市</li>
<li data-search="哈尔滨市haerbing">哈尔滨市</li>
<li data-search="长春市changchun">长春市</li>
<li data-search="兰州市lanzhou">兰州市</li>
<li data-search="北京市beijing">北京市</li>
<li data-search="杭州市hangzhou">杭州市</li>
<li data-search="长沙市changsha">长沙市</li>
<li data-search="沈阳市shenyang">沈阳市</li>
<li data-search="成都市chengdu">成都市</li>
<li data-search="合肥市hefei">合肥市</li>
<li data-search="天津市tianjin">天津市</li>
<li data-search="西安市xian">西安市</li>
<li data-search="武汉市wuhan">武汉市</li>
<li data-search="济南市jinan">济南市</li>
<li data-search="广州市guangzhou">广州市</li>
<li data-search="南京市nanjing">南京市</li>
<li data-search="上海市shanghai">上海市</li>
<li data-search="昆明市kunming">昆明市</li>
<li data-search="郑州市zhengzhou">郑州市</li>
<li data-search="贵阳市guiyang">贵阳市</li>
<li data-search="西宁市xining">西宁市</li>
<li data-search="海口市haikou">海口市</li>
<li data-search="南昌市nanchang">南昌市</li>
<li data-search="香港特区xianggang">香港特区</li>
<li data-search="澳门特区aomen">澳门特区</li>
</ul>
</div>
<script>
const inputEle = document.getElementById('inputEle');
const styleEle = document.createElement('style');
document.head.appendChild(styleEle);
inputEle.addEventListener('input', e => {
const value = e.target.value;
styleEle.innerHTML = value
? `[data-search]:not([data-search*=${value}]){display:none;}`
: '';
});
</script>
</body>
</html>