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
|
<!DOCTYPE html> <head> <meta http-equiv= "Content-Type"
content= "text/html; charset=utf-8"
/>
<title></title>
<script type= "text/javascript" >
window.onload = function
() {
// var str = "avdfklksd";
//alert(str.search(‘d‘));//找到字符串出现的位置,如果没找到返回-1
var
oName = document.getElementById( "txtname" );
var
oBtn = document.getElementById( "btnSearch" );
var
oTab = document.getElementById( "tb1" );
oBtn.onclick = function
() {
for
(i = 0; i < oTab.tBodies[0].rows.length; i++) {
var
oStr = oTab.tBodies[0].rows[i].cells[1].innerText.toLocaleLowerCase();
var
oText = oName.value.toLocaleLowerCase();
if
(oStr.search(oText) != -1) {
oTab.tBodies[0].rows[i].style.background = "yellow" ;
}
else
{
oTab.tBodies[0].rows[i].style.background = "" ;
}
}
}
}
</script>
</head> <body> <input type= "text"
name= "txtname"
id= "txtname"
/><input type= "button"
value= "搜索"
id= "btnSearch"
/>
<table id= "tb1"
border= "1"
style= "width: 500px;" >
<thead>
<tr>
<td>ID</td>
<td>姓名</td>
<td>年龄</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Cupid</td>
<td>66</td>
</tr>
<tr>
<td>2</td>
<td>Fly</td>
<td>45</td>
</tr>
<tr>
<td>3</td>
<td>Sky</td>
<td>23</td>
</tr>
<tr>
<td>4</td>
<td>Windy</td>
<td>98</td>
</tr>
<tr>
<td>5</td>
<td>Snow</td>
<td>09</td>
</tr>
</tbody>
</table>
</body> </html> |