如何使用 :contains 属性与 jquery

问题描述 投票:0回答:0

我想稍微改变一下我的功能并使用 :contains "value" 而不是等于值,这样搜索就不会那么挑剔了。我也必须使用

$(this)

 $("#searchTheKey").on('keyup', function(){
 var value = $(this).val().toLowerCase();
 $(".center-wrapper").each(function () {
    if ($(this).text().toLowerCase().search(value) > -1) {
        $(this).show();
       console.log("match found")
        } else {
        $(this).fadeOut(500);
        console.log("match not found")
    }
 });
 })

我想改变这条线

if ($(this).text().toLowerCase().search(value) > -1)

对于类似下面的内容,我已经看到了 :contains("value") 但它与 $(this) 不兼容

if ($(this):contains(value);

我也试过这个方法,但是它没有获取值var

 if($(this).is(':contains(value)')) 

任何帮助将不胜感激,或者另一种搜索方法也很好,

如果需要,这是我的 html

    <div class="center-wrapper {{ type }} {{ area }}">
    <div class="img" style="background-image: url({{ img }});"></div>

    <div class="column-1"> 
      <h2 class="location">{{ location }}</h2>
      <p class="type">Type: {{ type }}</p>
      <p class="address">{{ address }}</p>
    </div>

    <div class="column-2">
      <p class="email">{{ email }}</p>
      <p class="phone">{{ phone }}</p>

    </div>
   
   
   
  </div>
javascript jquery contains
© www.soinside.com 2019 - 2024. All rights reserved.