:contains() 选择器 - 如何忽略区分大小写?

时间:2021-08-01 23:15:36

标签: jquery

如何使用 :contains() 选择器忽略区分大小写?

            $('.css-label:contains("' + filter + '")').each(function () {
                $(this).show();
                $(this).prev().show().prev().show().closest(".search-recipe-chkbox").css("display", "inline-block");;
            });

上下文

        var input = $('.search-filter');
        input.change(function () {
            var filter = input.val().toLowerCase();
            if (filter.length == 0) { // show all if filter is empty
                $('.css-label').each(function () {
                    $(this).show();
                    $(this).prev().show().prev().show().closest(".search-recipe-chkbox").css("display", "inline-block");
                });
                return;
            }

            // hide all labels with checkboxes
            $('.css-label').each(function () {
                $(this).hide();
                $(this).prev().hide().prev().hide().closest(".search-recipe-chkbox").css("display", "none");;
            });

            // show only matched
            $('.css-label:contains("' + filter + '")').each(function () {
                $(this).show();
                $(this).prev().show().prev().show().closest(".search-recipe-chkbox").css("display", "inline-block");;
            });
        }).keyup(function () {
            $(this).change();
        });

谢谢

0 个答案:

没有答案
相关问题