Filter cards in Bootstrap 4 with jQuery

后端 未结 3 1363
闹比i
闹比i 2021-02-03 15:07

I am attempting to create a page that is populated by many cards, using bootstrap 4\'s new card component.

I want to create a search bar, that when searched, filters ou

3条回答
  •  [愿得一人]
    2021-02-03 15:52

    $(document).ready(function() {
        $('#searchForm').keyup(function(){
            search_text($(this).val());
        });
    
        function search_text(value){
            $('#search_section .card').each(function(){
                var found = 'false';
                $(this).each(function(){
                    if($(this).text().toLowerCase().indexOf(value.toLowerCase()) >= 0)
                    {
                        found = 'true';
                    }
                });
                if(found == 'true'){
                    $(this).show()
                }
                else {
                    $(this).hide();
                }
            })
        }
    });
    

提交回复
热议问题