您好,登錄后才能下訂單哦!
本文實(shí)例講述了JavaScript前端頁(yè)面搜索功能。分享給大家供大家參考,具體如下:
今天給大家分享一篇關(guān)于前端頁(yè)面搜索的案例,有了這個(gè)案例,在表格數(shù)據(jù)中可以進(jìn)行快速查找,比在瀏覽器中使用ctrl+F體驗(yàn)比較好。
效果圖:
代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>頁(yè)面搜索實(shí)例</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.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>移動(dòng)充值</td> <td>女</td> <td>10086</td> </tr> <tr> <td>聯(lián)通充值</td> <td>女</td> <td>10010</td> </tr> </table> <div ></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>
代碼比較簡(jiǎn)單,首先給button按鈕添加單擊事件,然后獲取文本框中的內(nèi)容,再?gòu)谋砀裰衪r進(jìn)行查找,首先把表頭的tr過(guò)濾掉,然后把其他的tr全部隱藏掉,然后按照內(nèi)容進(jìn)行過(guò)濾,把過(guò)濾出來(lái)的行顯示出來(lái)。
感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測(cè)試上述代碼運(yùn)行效果。
注:另外,本站如下幾款在線工具也具有前端頁(yè)面搜索功能,且功能更加強(qiáng)大:
php在線函數(shù)參考表:
http://tools.jb51.net/table/php_fun_table
全國(guó)少數(shù)民族分布在線查詢工具:
http://tools.jb51.net/bianmin/minzufenbu
世界節(jié)日在線查詢工具:
http://tools.jb51.net/bianmin/jieri
世界各國(guó)區(qū)號(hào)代碼及時(shí)差查詢表:
http://tools.jb51.net/bianmin/shicha
世界各國(guó)/地區(qū)貨幣查詢表:
http://tools.jb51.net/bianmin/huobi
世界各國(guó)首都查詢表:
http://tools.jb51.net/bianmin/shoudu
更多關(guān)于jQuery相關(guān)內(nèi)容可查看本站專題:《jQuery頁(yè)面元素操作技巧匯總》、《jQuery常見事件用法與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。