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

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?