无法尝试复制样式

时间:2017-05-23 16:52:42

标签: javascript html5 css3

我正在检查表格中的重复项。我想要完成的是当我显示第一列时,如果它与前一行的值相同,我不想显示该值。我找到了重复项,但是当我尝试使用显示隐藏它们时出现错误。 style =“none”;我的代码如下。

我提前感谢你 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; 



      }     
   }  

1 个答案:

答案 0 :(得分:0)

dvTable是一个HTML表格元素。您无法使用dvTable[i]访问该行。

尝试 -

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