嗨,我试图为跨度列表制作一个过滤器,我很难将跨度中的内容放到小写或忽略。 有什么想法吗?
$("#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();
});
答案 0 :(得分:0)
您将不得不自己检查每个跨度的内容。您可以使用.html()函数将每首歌曲/ grouptitle的内容作为字符串来实现。这样的东西可能会起作用(虽然我还没有测试过):
$("#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选择器区分大小写,我无法改变它。