首页 > 代码库 > jq contains实例

jq contains实例

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="http://www.mamicode.com/js/jquery-1.4.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
$("#sel").keyup(function(){
var $sel=$(this).val();
$("table tbody tr").hide().filter(":contains(‘"+$sel+"‘)").show();
});
});
</script>
</head>
<body>
<input type="text" id="sel"/>
<table border="1" width="500px" >
<thead>
<tr>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>班级</th>
</tr>
</thead>
<tbody>
<tr>
<td>s001</td>
<td>小白</td>
<td>女</td>
<td>t111</td>
</tr>
<tr>
<td>s002</td>
<td>小黑</td>
<td>男</td>
<td>t111</td>
</tr>
<tr>
<td>s003</td>
<td>小强</td>
<td>男</td>
<td>t112</td>
</tr>
<tr>
<td>s004</td>
<td>张三</td>
<td>男</td>
<td>t113</td>
</tr>
<tr>
<td>s005</td>
<td>小兰</td>
<td>女</td>
<td>t113</td>
</tr>
</tbody>
</table>
</body>
</html>

jq contains实例