Javascript 在带有jquery搜索列的html表中,获取值并删除行

Javascript 在带有jquery搜索列的html表中,获取值并删除行,javascript,jquery,html,search,html-table,Javascript,Jquery,Html,Search,Html Table,HTML: 我正确地动态添加值 我想进行搜索,如果myValue等于第3列TypeDistribution中的值,则在第1列计数器中获取该值并删除整行。我可以用jquery来实现它吗?如何实现 类型是文本, 计数器和类型分布是整数, 移除按钮 编辑: 这是你的答案 <table class="table" id="myTable"> <tr> <th>Type</th> <th>Counter<

HTML:

我正确地动态添加值

我想进行搜索,如果myValue等于第3列TypeDistribution中的值,则在第1列计数器中获取该值并删除整行。我可以用jquery来实现它吗?如何实现

类型是文本, 计数器和类型分布是整数, 移除按钮

编辑:

这是你的答案

<table class="table" id="myTable">
   <tr>
        <th>Type</th>
        <th>Counter</th>
        <th>Remove</th>
        <th style="display:none;">TypeDistribution</th>
   </tr>
</table>
HTML:-

$(document).ready(function(){
    var searchValue = 456; //lets say your value is 456
    $("table tr").each(function(){
       $(this).find('td').each(function(){
          var currentText = $(this).text();

          if(currentText == searchValue){
              $(this).parents('tr').remove();
          }
      });
   });
});

只需给第三列一个类,例如typeDistribution。您可以轻松地访问它,并查看它的父列和其他列

<table class="table" id="myTable">
    <tr>
      <th>Type</th>
      <th>Counter</th>
      <th>Remove</th>
      <th style="display:none;">TypeDistribution</th>
    </tr>
    <tr>
      <td>abc</td>
      <td>def</td>
      <td>ghi</td>
      <td>pqr</td>
    </tr>
    <tr>
      <td>123</td>
      <td>456</td>
      <td>789</td>
      <td>101</td>
    </tr>
</table>    
请尝试以下操作:

/**
 * Compare the given value with the third column
 * @param  {String} value The value to compare the thrd column with
 * @return {String}       The value from the first column
 */
function compare(value) {
    if ($('.typeDistribution').html() == value) {
        return $(this).parent().remove().children()[1].html();
    }
}

第1列和第3列的值是多少?您在该列中搜索的内容是什么?我尝试进行搜索,但无法完成所有操作。JQuery在这一点上让我感到困惑。TypeDistribution是数值0-9请显示一些带有值的html这是我第二次发布问题,很抱歉丢失了信息。您可能必须使用each循环,我现在不太确定。它对我有效。我想知道,为什么它不起作用。只需确保脚本应位于$document.ready中。在此之前,应该包括Jquery库。如果可能的话,你能告诉我你的错误是什么吗?
$(document).ready(function() {
  $('.button').on('click', function() {
    $('.table .values').each(function() {
      $('td').each(function() {
        if ($(this).text() == $(".select option:selected").val()) {
          var old = $('tr').find("td").eq(1).text();
          $('tr').find("td").eq(1).text(parseInt(old) + 1);
        } else {
          alert('not found');
        }
      })
    });
  });
})