0

まず、私は JS または Jquery が本当に苦手であることを認めなければなりません。jquery を使用して結果をフィルタリングするのに役立つコードを探しました。コードは次のとおりです。

$(document).ready(function(){
    $("#filter").keyup(function(){  
        // Retrieve the input field text and reset the count to zero        
        var filter = $(this).val(), count = 0;         
        // Loop through the comment list      
        $(".commentlist li").each(function(){           
            // If the list item does not contain the text phrase fade it out    
            if ($(this).text().search(new RegExp(filter, "i")) < 0) {     
                $(this).fadeOut();  
                // Show the list item if the phrase matches and increase the count by 1
            } else {     
                $(this).show();     
                count++;         
            }        
        });        
        // Update the count     
        var numberItems = count;
        $("#filter-count").text("Number of Comments = " + count);
    });
});

このコードは、以下にリストされている順序なしリストで機能します。

  <ol class="commentlist">  <li>Comment #1</li>  <li>Comment #2</li></ol> 

これで、このコードはリストでうまく機能します。それにもかかわらず、私は自分のサイトに行ごとに 3 つのレコードを持つテーブルを持っています。各レコード (セル) は、ユーザー プロファイルを表します。ユーザーがユーザー名を入力して表示できるように、この正確な検索機能をテーブルで機能させたいと思います。それは可能ですか?

みんなありがとう、そして本当にサポートに感謝します。

4

1 に答える 1

0
<script>
    $(document).ready(function(){
        $("#filter").keyup(function(){  
            // Retrieve the input field text and reset the count to zero        
            var filter = $(this).val(), count = 0;         
            // Loop through the comment list      
            $(".users td").each(function(){           
                // If the list item does not contain the text phrase fade it out    
                if ($(this).text().search(new RegExp(filter, "i")) < 0) {     
                    $(this).fadeOut();  
                    // Show the list item if the phrase matches and increase the count by 1
                } else {     
                    $(this).show();     
                    count++;         
                }        
            });        
            // Update the count     
            var numberItems = count;
            $("#filter-count").text("msg" + count);
        });
    });
</script>
于 2013-05-13T10:31:05.127 に答える