Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于jQuery的文本搜索/筛选可以工作,但并非适用于所有字段_Jquery - Fatal编程技术网

基于jQuery的文本搜索/筛选可以工作,但并非适用于所有字段

基于jQuery的文本搜索/筛选可以工作,但并非适用于所有字段,jquery,Jquery,我目前有一个基于jQuery的搜索,用于过滤卡片div,但它目前只适用于details字段中的文本。我希望它也适用于其他字段,例如title/tags/source,但我不确定如何做到这一点。jQuery脚本是: $(document).ready(function(){ $("#search").on("keyup", function() { var value = $(this).val().toLowerCase(); $('.highlight').hide();

我目前有一个基于jQuery的搜索,用于过滤卡片div,但它目前只适用于details字段中的文本。我希望它也适用于其他字段,例如title/tags/source,但我不确定如何做到这一点。jQuery脚本是:

$(document).ready(function(){
  $("#search").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $('.highlight').hide();
    $('.highlight:contains("'+value+'")').show();
  });
HTML中的每张卡片都是

<div class="highlight">
  <summary>
    <div class="info">
      <span class="title"><%=h.title%>,</span>
      <span class="comment"><%=h.comment%></span>
      <p class="source">
        <a href="<%-h.link%>"><%=h.source%></a>
        <span class="date"><%=h.date%></span>
      </p>
      <p>
        <% h.tags.forEach((t)=>{%>
          <% if (t) { %>
            <span class="tag"><%=t%></span>
          <% } %>
        <%})%>
      </p>
    </div>
    <details>
      <% h.content.forEach((d)=>{%>
          <p><%=d%></p>
      <%})%>
    </details>
  </summary>
</div>
试试这个:

 $("#search").on("keyup", function() {
    console.log('here')
    var value = $(this).val();//.toLowerCase();

    $('.highlight').hide();
    $('.highlight :contains('+value+')').parents('.highlight').show();


  });

您正在将搜索值转换为小写,但这与文本不匹配。如果你不想区分大小写,你必须在搜索时间内将文本转换成小写。不仅是输入值

似乎还存在区分大小写和不区分大小写的文本匹配问题。 尝试此操作,请检查是否存在语法错误:

$(document).ready(function(){
   $.expr[':'].containsIgnoreCase = function (n, i, m) {
        return jQuery(n).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
    };
   $("#search").on("keyup", function() {
       var value = $(this).val().toLowerCase();
       $('.highlight').hide();
       $('.highlight:containsIgnoreCase("'+value+'")').show();
   });
 });

这适用于标签,但仍然不适用于源代码或标题。对不起,我收回我最初的评论,这非常有效!