-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.html
More file actions
155 lines (145 loc) · 3.5 KB
/
Copy pathtest.html
File metadata and controls
155 lines (145 loc) · 3.5 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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7">
<meta name="description" content="简单搜索功能">
<meta name="keywords" content="简单搜索功能">
<title>简单搜索功能</title>
<style type="text/css">
#search{ width: 600px; margin: 50px auto;}
input{ vertical-align: middle;}
label{ display: inline-block;}
#sel{ width: 80px;}
#txt{ margin-bottom: 0;}
table{ margin-top: 20px; text-align: center; border: 1px solid #ccc;}
td{ width: 80px; height: 30px; font: 14px/30px SimSun;}
</style>
</head>
<script>
window.onload = function(){
var oTxt = document.getElementById('txt');
var oBtn = document.getElementById('btn');
var oSel = document.getElementById('sel');
var aRow = document.getElementById('table').tBodies[0].rows;
var type = 1; //搜索类别:姓名 年龄 性别 地区
oSel.onchange = function(){
type = oSel.value;
}
oBtn.onclick = function(){
var sTxt = oTxt.value.replace(/^s*|s*$/g, '');
if(sTxt){
var aTxt = sTxt.toLowerCase().split(' ');
for (var i = 0; i < aRow.length; i++) {
aRow[i].style.background = '';
for (var j = 0; j < aTxt.length; j++) {
if(aRow[i].cells[type].innerHTML.toLowerCase().search(aTxt[j]) != -1){
aRow[i].style.background = 'red';
}
};
};
}
}
}
</script>
<body>
<div class="container cls">
<div id="search">
<select name="" id="sel">
<option value="1">搜姓名</option>
<option value="2">搜年龄</option>
<option value="3">搜性别</option>
<option value="4">搜地区</option>
</select>
<input type="text" name="" id="txt">
<input type="button" value="搜索" id="btn" class="btn btn-primary">
<label for="btn">(多个关键词请以空格分隔)</label>
<table id="table" border="1" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td>序号</td>
<td>姓名</td>
<td>年龄</td>
<td>性别</td>
<td>所在地</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Jim</td>
<td>20</td>
<td>男</td>
<td>北京</td>
</tr>
<tr>
<td>2</td>
<td>Amy</td>
<td>18</td>
<td>女</td>
<td>上海</td>
</tr>
<tr>
<td>3</td>
<td>张三</td>
<td>22</td>
<td>男</td>
<td>南京</td>
</tr>
<tr>
<td>4</td>
<td>李四</td>
<td>19</td>
<td>女</td>
<td>上海</td>
</tr>
<tr>
<td>5</td>
<td>张五</td>
<td>24</td>
<td>男</td>
<td>北京</td>
</tr>
<tr>
<td>6</td>
<td>李六</td>
<td>19</td>
<td>男</td>
<td>上海</td>
</tr>
<tr>
<td>7</td>
<td>小明</td>
<td>20</td>
<td>男</td>
<td>南京</td>
</tr>
<tr>
<td>8</td>
<td>小红</td>
<td>22</td>
<td>女</td>
<td>上海</td>
</tr>
<tr>
<td>9</td>
<td>小兰</td>
<td>19</td>
<td>女</td>
<td>北京</td>
</tr>
<tr>
<td>10</td>
<td>John</td>
<td>18</td>
<td>男</td>
<td>上海</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html></td>
</tr>
</table>