如何仅显示具有匹配名称输入字段值的表单

How to show only those forms with a matching name input field value

本文关键字:输入 字段 表单 显示 何仅      更新时间:2023-09-26

我有一个页面,上面有很多表格。

Each form has a unique id.
Each form has a user name field.

的例子:

<form id="new_celebration692130342" accept-charset="UTF-8" action="/celebrations" method="post">
<input id="friend" type="hidden" name="celebration[friend_name]" value="Anthony Rosenfeld">
<input id="friend" type="hidden" name="celebration[friend_fbuid]" value="69213034***2">
<input id="friend" type="hidden" name="celebration[friend_birthday]" value="12/09">
<input id="friend" type="hidden" name="celebration[friend_pic]" value="http://graph.facebook.com/69213034***2/picture">
<li>Anthony Rosenfeld</li>
<li>12/09</li>
<input class="button-mini-subtle submit" type="submit" alt="select" value="select">
</form>

我想让用户能够输入一个名称或开始在搜索框中键入,javascript/jquery将运行,只显示与名称字段匹配的表单。

对于这类操作,我是一个主要的新手,如果有人指出正确的方向,我会很感激。

$(function () {
  $("#searchBox").keypress(function () {
    console.log($('input[name~="' + $(this).val() + '"]').parent('form'));
  });
});

这将把所有具有与searchBox值匹配的名称的输入子元素记录到控制台