dounei5721 2019-02-08 11:42
浏览 80
已采纳

在Jquery中搜索区域,用于在另一个输入的输入网格中搜索

I wish to search from an input (type="text") in a grid (like table but made in .css for be responsive so with div ans span in html) if input (type="text"). (I precise than this grid in imported from sql sever by php). I don't knw what wrong in my code but it's hide evreything.

I tried http://jsfiddle.net/FranWahl/rFGWZ/ by modifing of course what I needed (so #search by #searchName; table tr by .grid ->class of my div(s); td by span and .text() by .val()-> actually I tried both )

//so here my .js

$(function() {
  $("#searchCode").on("keyup", function() {
    var value = $(this).val();

    $(".grid").each(function(index) {
      if (index !== 0) {
        $row = $(this);
        var id = $row.find("span:nth-child(1)").val();
        if (id.indexOf(value) !== 0) {
          $row.hide();
        }
        else {
          $row.show();
        }
      }
    }); 
  });
});

//here my php

<form action="menu.php?Option=SelectIgr" method="post">
    <div id="titleRow" class="grid">
        <span class="cellCode titleCell"><button name="order" class="titlebutton" type="submit" value="orderByCode">Code</button></span>
        <span class="cellName titleCell"><button name="order" class="titlebutton" type="submit" value="orderByName">Name</button></span>
        <span class="cellEdit titleCell">Edit</span>
        <span class="cellDelete titleCell">Delete</span>
    </div>
</form>

<?php foreach($ingredients as $object)
{ ?>
    <form method="post" id=<?=$object->code()?>>
        <div class="grid">
            <span class="cellCode"><input type="text" name="code" value=<?=$object->code()?>></span>
            <span class="cellName"><input type="text" name="name" value=<?=$object->name()?>></span>
            <span class="cellEdit"><button class="ButtonEdit" type="submit" formaction="/action_edit.php"></button></span>
            <span class="cellDelete"><button class="ButtonDelete" type="submit" formaction="/action_delete.php"></button></span>
        </div>
    </form>

<?php } ?>

I expected that in live it would hide line that I don't whant like here http://jsfiddle.net/FranWahl/rFGWZ/ but it's hide everything (like if it didn't show the value on id

  • 写回答

1条回答 默认 最新

  • duandeng7132 2019-02-08 13:43
    关注

    Omg I am so st**id today, I should sleep, for those which didn't seen the solution : I attribut my classes to span instead of input facepalm and i try to take the values of the span instread of the input. Sorry

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题