Javascript 使用“显示”时取消选中复选框;无”;几排

Javascript 使用“显示”时取消选中复选框;无”;几排,javascript,jquery,checkbox,Javascript,Jquery,Checkbox,嗨,伙计们, 我正在尝试更改“全部检查”按钮,以仅检查可见的行。 不幸的是,我没有看到如何只处理可见的行。 我试过这样的方法,但没有成功 $("#checkAll").click(function(){ if(!x){ if($(".check").is("visible")){ $(':checkbox').each(function(){ this.checked = true; });} x=true;}

嗨,伙计们, 我正在尝试更改“全部检查”按钮,以仅检查可见的行。 不幸的是,我没有看到如何只处理可见的行。 我试过这样的方法,但没有成功

$("#checkAll").click(function(){
    if(!x){
        if($(".check").is("visible")){
        $(':checkbox').each(function(){ this.checked = true; 

        });}

        x=true;}

    else{
        $(':checkbox').each(function(){ this.checked = false; });
        x= false;
        }});
我就是这样过滤我的桌子的

function abtFilter() {
      // Declare variables
      var input, filter, table, tr, td, i, txtValue;
      input = document.getElementById("searchbar");
      filter = input.value.toUpperCase();
      table = document.getElementById("notfallTable");
      tr = table.getElementsByTagName("tr");
      // Loop through all table rows, and hide those who don't match the search query
      for (i = 0; i < tr.length; i++) {
        td = tr[i].getElementsByTagName("td")[3];
        if (td) {
          txtValue = td.textContent || td.innerText;
          if (txtValue.toUpperCase().indexOf(filter) > -1) {
            tr[i].style.display = "";
          } else {
            tr[i].style.display = "none";
            $("")
          }
        }
      }
    }
函数abtFilter(){
//声明变量
var输入、过滤器、表格、tr、td、i、TXT值;
输入=document.getElementById(“搜索栏”);
filter=input.value.toUpperCase();
table=document.getElementById(“notfallTable”);
tr=table.getElementsByTagName(“tr”);
//循环遍历所有表行,并隐藏与搜索查询不匹配的行
对于(i=0;i-1){
tr[i].style.display=“”;
}否则{
tr[i].style.display=“无”;
$("")
}
}
}
}
这就是桌子的样子

        items.push("<td class='numbers' contenteditable>"+val.Nummer+"</td>");
        items.push("<td contenteditable>"+val.Typ+"</td>");
        items.push("<td contenteditable>"+val.Vorname+"</td>");
        items.push("<td contenteditable>"+val.Nachname+"</td>");
        items.push("<td contenteditable>"+val.Abteilung+"</td>");

        items.push("<td class='check'><label><input type='checkbox'>"+""+"</input></label></td>");

        items.push("</tr>");
items.push(“+val.numer+”);
items.push(“+val.Typ+”);
items.push(“+val.Vorname+”);
items.push(“+val.Nachname+”);
推送(“+val.Abteilung+”);
items.push(“+”+”);
项目。推送(“”);

您可以直接使用复选框上的
:visible
选择器。还要注意,您不需要
each()
循环;您可以设置
checked
属性,jQuery将自动为您遍历所有选定的元素。试试这个:

$(“#全选”)。单击(函数(){
$(':复选框:可见').prop('checked',!x);
x=!x;
});

尝试创建一个最小的工作示例。另外,请尝试将您的代码放入可运行的代码段(使用
Ctrl+M
插入),以便我们能够准确地看到问题所在以及您想要的内容。嘿。下面的答案已经起作用了。但是谢谢你的努力我很想知道你已经收到了答复。尽管如此,始终尝试通过提及问题和您想要的解决方案并创建一个最小的工作示例来提问。这真的帮助了你和潜在的回答者。没问题,很乐意帮助。