【发布时间】:2019-02-08 11:42:39
【问题描述】:
如果输入 (type="text"),我希望从网格中的输入 (type="text") 搜索(如表格,但在 .css 中制作以便响应,因此在 html 中使用 div 和 span)。 (我比 php 从 sql sever 导入的这个网格更精确)。我不知道我的代码有什么问题,但它隐藏了一切。
我尝试了http://jsfiddle.net/FranWahl/rFGWZ/,当然修改了我需要的东西(所以#search by #searchName;table tr by .grid ->class of my div(s); td by span 和 .text() by .val( )-> 其实我都试过了)
//这里是我的 .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();
}
}
});
});
});
//这里是我的 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 } ?>
我希望在现场直播中它会隐藏我不喜欢的行 http://jsfiddle.net/FranWahl/rFGWZ/ 但它会隐藏所有内容(比如它没有显示 id 上的值
【问题讨论】:
-
我准确地说这是我的第二个 .val() 不起作用,因为如果我执行 alert(id) 它是空的:/ 是问题,而不是来自 php 函数的值不工作?那我该怎么办?