检索table表格数据代码实例

快乐打工仔 分类:实例代码

本章节分享一段代码实例,它实现了检索表格中数据的功能。

代码实例如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.pipipi.net/" />
<title>前端教程网</title>
<style>
table {
  width: 700px;
  border-collapse: collapse;
  margin-top: 15px;
}
td {
  padding: 10px;
  border: 1px solid #CCCCCC;
}
</style>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
  $("#searchBtn").click(function(){
    $("table tr:not(':first')").hide().filter(":contains('"+$("#searchCon").val()+"')").show();
  })
})
</script>
</head>
<body>
<input type="text" id="searchCon">
<input type="button" id="searchBtn" value="搜索">
<table>
  <tr>
    <td>前端教程网一</td>
    <td>前端教程网二</td>
    <td>前端教程网三</td>
  </tr>
  <tr>
    <td>antzone</td>
    <td>softwhy</td>
    <td>前端教程网</td>
  </tr>
  <tr>
    <td>div教程</td>
    <td>css教程</td>
    <td>css教程</td>
  </tr>
  <tr>
    <td>js教程</td>
    <td>jquery教程</td>
    <td>ts教程</td>
  </tr>
  <tr>
    <td>json教程</td>
    <td>ajax教程</td>
    <td>es6教程</td>
  </tr>
</table>
</body>
</html>

上面的代码实现了我们的要求,代码非常简单,更多内容可以参阅相关阅读。

相关阅读:

(1).:not()可以参阅jQuery :not一章节。

(2).:first可以参阅jQuery :first一章节。

(3).filter()可以参阅jQuery filter()一章节。

(4).:contains可以参阅jQuery :contains一章节

检索table表格数据代码实例,这样的场景在实际项目中还是用的比较多的,关于检索table表格数据代码实例就介绍到这了。

检索table表格数据代码实例属于前端实例代码,有关更多实例代码大家可以查看

回复

我来回复
  • 暂无回复内容