0

嗨,我试图为跨度列表制作过滤器,我无法将跨度中的内容转换为小写或忽略大小写。有任何想法吗?

 $("#filterinput2").keyup(function () {
            var filter = ($(this).val()).toLowerCase(); // get the value of the input, which we filter on
            console.log("lower filter" + filter);
            if (filter) {         
                // hide tr's for songs not matching and show tr's for songs matching
                $(".tonelist").find(".song:not(:contains(filter))").parent().parent().parent().fadeOut("slow");
                $(".tonelist").find(".song:contains(filter)").parent().parent().parent().fadeIn();
                if (window.console != undefined) {
                    console.log($(".tonelist").find(".song:not(:contains(" + filter + "))").parent().parent().parent().innerHTML);
                }

                $(".tonelist").find(".grouptitle:not(:contains(" + filter + "))").parent().fadeOut("slow");
                $(".tonelist").find(".grouptitle:contains(" + filter + ")").parent().fadeIn();
                if (window.console != undefined)
                    console.log($(".tonelist").find(".grouptitle:not(:contains(" + filter + "))").parent().parent().parent().innerHTML);
            } else
            // if input field is empty, show all tr's
                $(".tonelist").find("tr").fadeIn();

            ColorLines();
        });
4

1 回答 1

0

您将不得不自己检查每个跨度的内容。您可以使用 .html() 函数将每首歌曲/组标题的内容作为字符串获取。像这样的东西可能会起作用(尽管我还没有测试过):

    $("#filterinput2").keyup(function () {
        var filter = ($(this).val()).toLowerCase(); // get the value of the input, which we filter on
        console.log("lower filter" + filter);
        if (filter) {         
            // hide tr's for songs not matching and show tr's for songs matching
            spans = $(".tonelist").find(".song, .grouptitle")
            for (s in spans) {
                el = $(spans[s]);
                if ( el.html().match( new RegExp(filter, "i") ) ) {
                    el.fadeIn();
                } else {
                    el.fadeOut("slow");
                }
            }
        } else
        // if input field is empty, show all tr's
            $(".tonelist").find("tr").fadeIn();

        ColorLines();
    });

原因是 :contains() css 选择器区分大小写,我不知道如何更改它。

于 2012-04-24T14:22:58.237 回答