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

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

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符