Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调整表的jQuery搜索_Jquery_Search_Html Table - Fatal编程技术网

调整表的jQuery搜索

调整表的jQuery搜索,jquery,search,html-table,Jquery,Search,Html Table,我有一个表的搜索功能,我想调整它,只在标题列中查找匹配项。并隐藏与标题文本不匹配的所有项目。我的代码 JS HTML Handlingar Title在你的js中尝试一下。希望它能起作用 $(document).ready(function() { var $rows = $('#table tbody tr'); $('#search').keyup(function () { var val = $.trim($(this).val()).rep

我有一个表的搜索功能,我想调整它,只在标题列中查找匹配项。并隐藏与标题文本不匹配的所有项目。我的代码

JS

HTML


Handlingar

Title在你的js中尝试一下。希望它能起作用

$(document).ready(function() {
      var $rows = $('#table tbody tr');
      $('#search').keyup(function () {
          var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();

          $rows.show().filter(function () {
              var text = $($(this).find('td')[1]).text().replace(/\s+/g, ' ').toLowerCase();
              return !~text.indexOf(val);
          }).hide();
      });
});

你的代码对我来说很好是的,但它会在所有Coulmn上搜索。我想缩小范围,只查找标题栏中的匹配项。我已经修改了jusy
var text=$($(this).find('td')[1]).text().replace(/\s+/g',).toLowerCase()行我自己就这样解决了:
var text=$(this).children(“:eq(“+”1“+”)).text().replace(/\s+/g').toLowerCase()你认为巫婆一号更好吗?顺便说一下,这两个都可以,因为只有5个可以搜索。你可以随意使用:)“试试这个”并不能解释什么是不同的或者为什么它有用
         <table id="table" class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>Handlingar</th>
                    <th>Title</th>  <-----This column----
                    <th>Pris i kr</th>
                    <th>Skapad</th>
                    <th>Kategori</th>
                </tr>
            </thead>
            <tbody>
                @foreach (BuyAndSellAppWeb.Models.Advertisment objProduct in Model)
                {
                    <tr>
                        @if (objProduct.SellerToken)
                        {
                            <td>

                                @Html.ActionLink("Ändra", "Edit", new { id = objProduct.ID }) | @Html.ActionLink("Radera", "DeleteItem", new { id = objProduct.ID }) | @Html.ActionLink("Detaljer", "Details", new { id = objProduct.ID })

                        </td>
                        }
                        else
                        {
                            <td>
                                @Html.ActionLink("Detaljer", "Details", new { id = objProduct.ID })
                            </td>
                        }
                        <td>@objProduct.ProductTitle</td>
                        <td>@objProduct.Price kr</td>
                        <td>@objProduct.Created.ToString("yyyy/MMM/dd")</td>
                        <td id="category">@objProduct.Category</td>
                    </tr>
                }
            </tbody>
        </table>
$(document).ready(function() {
      var $rows = $('#table tbody tr');
      $('#search').keyup(function () {
          var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();

          $rows.show().filter(function () {
              var text = $($(this).find('td')[1]).text().replace(/\s+/g, ' ').toLowerCase();
              return !~text.indexOf(val);
          }).hide();
      });
});