在Chrome中使用.contains()jQuery函数时出错 [英] Error using .contains() JQuery function in Chrome

查看:95
本文介绍了在Chrome中使用.contains()jQuery函数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我致电.contains

When I call .contains in

if ($(this).text().toUpperCase().contains(word)

Chrome浏览器返回错误Uncaught TypeError:Object

Chrome returns an error 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();
            }
        });
    });
});

推荐答案

嘿,jQuery中的内容有所不同.. https://api.jquery.com/jQuery.contains/

hey contains is different in jquery..https://api.jquery.com/jQuery.contains/

尝试:

var txt = $(this).text().toUpperCase();
var contains = (txt.indexOf(word) > -1);

那会给你一个包含的内容.

that'll give you a bool in contains.

编辑 这是您的新代码.

$(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中使用.contains()jQuery函数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆