想要遍历html表并检查第一个单元格数据是否重复? [英] Want to iterate through html table and check first cell data is duplicated?

查看:83
本文介绍了想要遍历html表并检查第一个单元格数据是否重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个html表'tab1'



Hi,

I have one html table 'tab1'

<table id="tab1">
               <tr>
                   <th>Empno</th>
                   <th>Ename</th>
                   <th>Salary</th>
               </tr>
               <tr>
                   <td>1</td>
                   <td>A</td>
                   <td>1000</td>
               </tr>
               <tr>
                   <td>1</td>
                   <td>A</td>
                   <td>1000</td>
               </tr>
               <tr>
                   <td>1</td>
                   <td>B</td>
                   <td>2000</td>
               </tr>
               <tr>
                   <td>2</td>
                   <td>C</td>
                   <td>3000</td>
               </tr>
               <tr>
                   <td>3</td>
                   <td>D</td>
                   <td>4000</td>
               </tr>
               <tr>
                   <td>3</td>
                   <td>A</td>
                   <td>1000</td>
               </tr>
           </table>





我想查看第一行的每一行。如果多次使用该行第一个单元格的相同数据然后想要将其设为不可见的假。

我尝试但无法实现。



任何人都可以帮我完成这个。



I want to check with every row first column. If more than one time with same data of that row first cell then want to make it as invisible false.
I tried but not able to achieve.

Can any one help me to complete this.

推荐答案

和Sergy Alexandrovich Kryukov一起,如果你不使用jquery

然后尝试以下方法:

Along with Sergy Alexandrovich Kryukov, if you are not using jquery
then try the following:
var tbl1=document.getElementById("tab1"); 
//alt 
var tbl1=document.querySelector("#tab1"); 

    for(var i=0;i<tbl1.rows.length;i++){>
      whatever_function(tbl1.rows[i].cells[0].innerHTML);
    }


感谢大家的解决方案


请参阅我对该问题的评论。实际上使用jQuery,而不只是标记它:

http://api.jquery.com/category/traversing



另一个想法:如果你已经知道结构(每行有多少个单元格,首先),你可以简单地拿走所有< td> 元素并遍历集合:

Please see my comment to the question. Actually use jQuery, not just tag it:
http://api.jquery.com/category/traversing.

Another idea: if you already know the structure (how many cells per row, first of all), you can simply take all the <td> elements and iterate through the set:
var allCells =


这篇关于想要遍历html表并检查第一个单元格数据是否重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆