JavaScript案例—页面搜索
2016-11-12 11:20
281 查看
今天给大家分享一篇关于前端页面搜索的案例,有了这个案例,在表格数据中可以进行快速查找,比在浏览器中使用ctrl+F体验比较好。
效果图:
代码:
代码比较简单,首先给button按钮添加单击事件,然后获取文本框中的内容,再从表格中tr进行查找,首先把表头的tr过滤掉,然后把其他的tr全部隐藏掉,然后按照内容进行过滤,把过滤出来的行显示出来。
效果图:
代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>页面搜索实例</title> <script src="jquery.js"></script> <style> table{ width:400px; border:1px solid blue; border-collapse: collapse; } table th{ height:30px; border:1px solid blue; text-align: center; } table td{ height:30px; border:1px solid blue; text-align: center; } </style> </head> <body> <table> <tr> <th>姓名</th> <th>性别</th> <th>电话</th> </tr> <tr> <td>张三</td> <td>男</td> <td>13111112222</td> </tr> <tr> <td>李四</td> <td>男</td> <td>13233334444</td> </tr> <tr> <td>移动充值</td> <td>女</td> <td>10086</td> </tr> <tr> <td>联通充值</td> <td>女</td> <td>10010</td> </tr> </table> <div style="width:100%;height:20px"></div> <div> <input type="text" name="" id=""> <input type="button" value="搜索"> </div> </body> <script> $('input[type=button]').click(function(){ var text = $('input[type=text]').val(); $('table tr').not(':first').hide().filter(':contains("'+text+'")').show(); }); </script> </html>
代码比较简单,首先给button按钮添加单击事件,然后获取文本框中的内容,再从表格中tr进行查找,首先把表头的tr过滤掉,然后把其他的tr全部隐藏掉,然后按照内容进行过滤,把过滤出来的行显示出来。
相关文章推荐
- 一段javascript的页面搜索代码
- JavaScript控制页面显示和隐藏带案例
- 一段javascript的页面搜索代码
- javascript 句柄传值 两个页面案例
- 使用 Rico JavaScript 库、ColdFusion MX 7 和 Windows Indexing Service 构建一个启用 Ajax 的搜索页面
- 用户控件中使用了Javascript ,把2个控件放在页面上,那么页面上会有2个同名的javascript函数,如何处理
- javascript,取得页面参数
- 小技巧:(javascript)如何让用户自由控制html页面大段文字的行间距和背景颜色
- JavaScript在页面间数据传输的使用
- aspx页面javascript的几个trick
- 再谈用javascript实现页面刷新后跳转菜单的定位[原创]
- JavaScript在页面间数据传输的使用
- Javascript技巧之弹出页面
- [收藏]用JavaScript让弹出页面以最小化的形式出现在状态栏中
- 厌倦了闪动的页面?来试试 javascript+WebService 吧!
- 用asp编写文档搜索页面
- 如何在jsp页面中引入css样式表文件和javascript文件
- “当页面跳转或者关闭窗口时弹出提示窗口!”JAVASCRIPT实例
- 用javascript实现页面刷新后跳转菜单的定位[原创]