<!DOCTYPE html>
<html xmlns= "http://www.w3.org/1999/xhtml" >
<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>
|