Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.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
Javascript 表THAD颜色复选框选中/取消选中_Javascript_Html_Checkbox_Colors_Html Table - Fatal编程技术网

Javascript 表THAD颜色复选框选中/取消选中

Javascript 表THAD颜色复选框选中/取消选中,javascript,html,checkbox,colors,html-table,Javascript,Html,Checkbox,Colors,Html Table,我对表格中的所有复选框有一个简短的问题。我不想改变颜色的第一个thead tr,如何删除标题的颜色 我粘贴代码,只使用纯Javascript function allpart(chk){ var parent = chk.parentNode.parentNode; var checkboxes = document.getElementsByTagName('input'); var chkpart = document.getElementById('idpart')

我对表格中的所有复选框有一个简短的问题。我不想改变颜色的第一个thead tr,如何删除标题的颜色

我粘贴代码,只使用纯Javascript

function allpart(chk){
    var parent = chk.parentNode.parentNode;
    var checkboxes = document.getElementsByTagName('input');
    var chkpart = document.getElementById('idpart');
    if(chk.checked){
        for(var i=0;i<checkboxes.length;i++){
            if(checkboxes[i].type == 'checkbox'){
                checkboxes[i].checked = true;
                checkboxes[i].parentNode.parentNode.style.background = "#CC0000";
                checkboxes[i].parentNode.parentNode.style.color = "#FFF";
            }
        }
    }else{
        for(var i=0;i<checkboxes.length;i++){
            if(checkboxes[i].type == 'checkbox'){
                checkboxes[i].checked = false;
                checkboxes[i].parentNode.parentNode.style.background = "";
                checkboxes[i].parentNode.parentNode.style.color = "";   
            }
        }
    }
函数所有部分(chk){
var parent=chk.parentNode.parentNode;
var复选框=document.getElementsByTagName('input');
var chkpart=document.getElementById('idpart');
如果(已检查){

对于(var i=0;i使用基于ad或tbody的条件设置颜色。例如,如果
复选框[i]。父(“tbody”).is(“tbody”)
,则设置颜色。

如果要从标题中删除颜色,请不要写入:

checkboxes[i].parentNode.parentNode.style.background = "";
只写:

checkboxes[i].parentNode.parentNode.style.background = "transparent";

这部分代码将删除所有
th
s的
color
background

var th = document.getElementsByTagName('th');
  for (var i = 0; i < th.length; i++) {
  th[i].style.color = "black";
  th[i].style.background = "white";
}
var th=document.getElementsByTagName('th');
对于(变量i=0;i
我认为这部分代码也是错误的。我将起始索引从2更改为0

for (var i = 0; i < checkboxes.length; i++) {
  if (checkboxes[i].type == "checkbox") {
    checkboxes[i].checked = false;
    checkboxes[i].parentNode.parentNode.style.background = "";
    checkboxes[i].parentNode.parentNode.style.color = "";
  }
}
for(变量i=0;i
希望这对你有帮助

函数所有部分(chk){
var parent=chk.parentNode.parentNode;
var复选框=document.getElementsByTagName(“输入”);
var chkpart=document.getElementById(“idpart”);
如果(已检查){
对于(变量i=0;i

名称
数字
第1行
第2排
第1行
第2排
第1行
第2排

你能添加你的html吗\你为什么从第2行开始?我更正了我没有注意到你说过的话。我学习了stackoverflow平台的用法。欢迎你。如果答案是真的,你可以接受。祝你好运。我建议你读一下@Kais