Javascript 在Chrome中使用.contains()JQuery函数时出错

Javascript 在Chrome中使用.contains()JQuery函数时出错,javascript,jquery,Javascript,Jquery,当我打电话的时候。包含在 if ($(this).text().toUpperCase().contains(word) Chrome返回一个错误Uncaught TypeError:Object <input id="busca_prof" class="campo_filtro" type="text" name="word" placeholder="pesquisar profissional"> <div id="prof_{{ prof.id }}" class

当我打电话的时候。包含在

if ($(this).text().toUpperCase().contains(word)
Chrome返回一个错误Uncaught TypeError:Object

<input id="busca_prof" class="campo_filtro" type="text" name="word" placeholder="pesquisar profissional">

<div id="prof_{{ prof.id }}" class="profissional filtrar">
   ... content
</div>

$(document).ready(function(){
    $(".campo_filtro").keyup(function(){
        word = $(this).val().toUpperCase();

        $(".filtrar").each(function(){
            if ($(this).text().toUpperCase().contains(word) ||
                removeAcento($(this).text().toUpperCase()).contains(word)){
                $(this).fadeIn();
            }else{
                $(this).fadeOut();
            }
        });
    });
});

... 内容
$(文档).ready(函数(){
$(“.campo_filtro”).keyup(函数(){
word=$(this.val().toUpperCase();
$(“.filtrar”).each(函数(){
如果($(this).text().toUpperCase()包含(word)||
removecento($(this).text().toUpperCase()).contains(word)){
$(this.fadeIn();
}否则{
$(this.fadeOut();
}
});
});
});

它们包含的内容在jquery中是不同的

试试这个:

var txt = $(this).text().toUpperCase();
var contains = (txt.indexOf(word) > -1);
那会让你大吃一惊的

编辑 这是你的新密码

$(document).ready(function(){
$(".campo_filtro").keyup(function(){
    word = $(this).val().toUpperCase();

    $(".filtrar").each(function(){
        if ($(this).text().toUpperCase().indexOf(word) != -1 ||
            removeAcento($(this).text().toUpperCase()).indexOf(word) != -1){
            $(this).fadeIn();
        }else{
            $(this).fadeOut();
        }
    });
});
});

Chrome还没有实现这个方法。另外,您应该在
keyup
处理程序中声明
word
变量,在窗口范围内隐式声明它的那一分钟,这就是“contains”的用途吗?我以为这是针对对象中的父子关系…是的,它不是字符串/子字符串匹配。。它返回了元素数组。哇,真的吗?它不应该是lol:D也许在firefox中它会返回字符串数组?真的很奇怪。@rayashi它在Firefox中确实有效。正如我提供的MDN链接中所述。这在其他任何情况下都不起作用。如果答案对你有帮助,请接受它:)@rayashi