如何使用jquery实现像ctrl + f这样的搜索

Mr *_*ide 3 html javascript php search jquery

嗨,我想在页面table tbody上搜索,搜索应该像ctrl + F搜索我html和我的PHP代码:

请参阅下面链接的图片和链接以获取来源.

    <table>
    <thead>
    <tr><td><input type="text" placeholder="Search Student id="searchStudent"> </td>
    <td></td><td></td><td></td><td></td><td></td></tr>
    </thead>

    <tbody>
    <tr>
    <td>
     <span><img src="<?php echo $gdScoreData['profile_pic']; ?>"/></span>
        <p><?php echo $gdScoreData['student_fname'];?> <?php echo $gdScoreData['student_lname'];?></p>
<p><b>Hallticket</b> : S<?php echo $gdScoreData['student_pid']; ?>J<?php echo $jobID; ?></p>
         </td>
    <td></td><td></td><td></td><td></td><td></td></tr>
Run Code Online (Sandbox Code Playgroud)

第1个tr将关闭这里PHP代码是上面的一个在HTML中它看起来像图像中所示:

<tr><td><span><img src="profile_pic/first_1479536519.jpg" width="50" /></span><p>Robert Smith</p><p><b>Hallticket</b> : S27J2</p></td></tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

这个我的javascript代码搜索如ctrl + F.

/* Search Student like ctrl+f start */
$("#searchStudent").on("keyup", function() {
    var value = $(this).val();
    console.log(value);
    $("table tbody tr").each(function(index) {
        if (index !== 0) {

            $row = $(this);

            var id = $row.find("td:first").text();

            if (id.indexOf(value) !== 0) {
                $row.hide();
            }
            else {
                $row.show();
            }
        }
    });
});
/* Search Student like ctrl+f end*/
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

以下是我尝试过的来源: Source JS

小智 6

我现在修改你的js小提琴代码jsfiddle.net/rFGWZ/3406/

       $("#search").on("keyup", function() {
        var value = $(this).val();
       if(value!='') {
           $("table tbody tr").hide();
       }else{
           $("table tbody tr").show();
       }
         $('table tbody tr td:contains("'+value+'")').parent('tr').show(); 
       });
Run Code Online (Sandbox Code Playgroud)