| js遍历table某一列内容出现的次数记录
					当前位置:点晴教程→知识管理交流
					
					→『 技术文档交流 』
					
				 
  :js遍历table某一列内容出现的次数记录  <script> function countvalueshow(myTable,colindex){ const table = document.getElementById(myTable); const rows = table.getElementsByTagName('tr'); const colCount = colindex; // 第二列的索引是1,因为索引从0开始计算 let countMap = {}; 
 for (let i = 1; i < rows.length; i++) { // 跳过表头 const cell = rows[i].getElementsByTagName('td')[colCount]; const age = cell.textContent.trim(); 
 if (countMap[age]) { countMap[age]++; } else { countMap[age] = 1; } } console.log(countMap); return countMap; } countvalueshow('myTable',1) 
 </script> 该文章在 2024/12/5 17:19:01 编辑过 | 关键字查询 相关文章 正在查询... |