$(this).hide() 隐藏它不应该隐藏的容器

$(this).hide() hides containers it shouldn't

我有一小段代码可以过滤结果列表并隐藏不匹配的 div。我正在为 PhoneGap iOS 应用程序编写此代码。它在 Android 上运行良好,但在 iOS 上,出于某种原因,它会在输入几个字符后隐藏整个搜索字段,而不仅仅是结果。

知道为什么吗?我已将其精简到几乎只有 HTML 代码和 jQuery,而且它仍在发生。我尝试注释掉 $(this).hide(); 部分,它不再隐藏搜索字段,所以我假设这就是罪魁祸首,但我不知道为什么或如何解决这个问题。连续工作了 10 个小时。有任何想法吗?也许我可以通过其他方式定位结果?

$('#box_search').keyup(function() {

  var valThis = $(this).val().toLowerCase();

  if (valThis == "") {
    $('#listing-results > .listing_container').show();

  } else {
    $('#listing-results > .listing_container').each(function() {    
      var text = ($(this).find('.listing_results_text_name').text() + $(this).find('.listing_results_text_name').data("alt")).toLowerCase();

      if (text.indexOf(valThis) >= 0) {
        $(this).show();
      } else {
        $(this).hide();
      }
    });
  };
});

显然我看不到 html 但有时它有助于清理代码并稍微更改逻辑

var box_search = function(e){

  var myIndex = $(this).val();
  val = (!myIndex || myIndex==='')?false:myIndex;

  if(!myIndex){
    $('#listing-results > .listing_container').show();
    return;
  }

  //
  $('#listing-results > .listing_container').each(function() {

    var text = $(this).find('.listing_results_text_name').text() + 
               $(this).find('.listing_results_text_name').data("alt")

    text = (!text || text==='')?false:text;

    text = text.toLowerCase();

    if(text.indexOf(myIndex.toLowerCase()) >= 0){
     $(this).show();
      return;
    }
    $(this).hide();
  });

} //end of function

$('.box_search').keyup(box_search);