简体   繁体   English

尝试为重复项设置样式时遇到麻烦

[英]Having trouble trying to style duplicates

I'm checking for duplicates in a table. 我正在检查表中的重复项。 What I'm trying to accomplish is when I display the first column if it is the same value as the previous row I don't want to display the value. 我要完成的是在显示第一列时,如果该列的值与我​​不想显示的前一行的值相同。 I'm finding the duplicates but I get an error when I try to hide them by using display. 我正在找到重复项,但是当我尝试使用display隐藏它们时出现错误。 style ="none"; style =“ none”; My code is below. 我的代码如下。

I'm Thanking You In Advance PD 我先谢谢你PD

 var data=[['e',0,1,2,3,4], ['a',54312,235,5,15,4], ['a',6,7,8,9,232],
     ['a',54,11235,345,5,6], ['b',0,1,2,3,4], ['b',54312,235,5,15,4],
     ['c',62,15,754,93,323], ['d',27,11235,425,18,78], ['d',0,1,2,3,4],
     ['d',54312,235,5,15,4], ['e',6,7,8,9,232], ['e',54,11235,345,5,6],
     ['e',0,1,2,3,4], ['e',54312,235,5,15,4], ['e',62,15,754,93,323], 
     ['e',27,11235,425,18,78]];


 //Create a HTML Table element.
     var table = document.createElement("TABLE");
     var somedata = document.createElement("TD");
     var dvTable = document.getElementById("dvTable");
     var elems = document.getElementsByClassName("tableRow");


  //Get the count of columns.
  var columnCount = data[0].length;

    //Add the data rows.  
   for (var i = 0; i < data.length; i++) {  
   var row = table.insertRow(-1);
      for (var j = 0; j < columnCount; j++) { 
      //Searching for duplicates            
           var num = data[i][0];
         for (var otherRow = i + 1; otherRow < data.length; otherRow++) {           
            var dup =  data[otherRow][0];
               console.log("What is the dup" + dup);
            if (num === dup)
            { 
                 console.log("duplicate");
                 dvTable[i].style.display = "none";
            }
         }


            var cell = row.insertCell(-1);                    
            cell.innerHTML = data[i][j];
            cell.innerHtml = myZero; 



      }     
   }  

dvTable is an HTML table element. dvTable是HTML表格元素。 You can't access the row using dvTable[i] . 您无法使用dvTable[i]访问该行。

Try - 尝试-

dvTable.rows(i).cells(j).style.display = none;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM