js遍歷table某一列內(nèi)容出現(xiàn)的次數(shù)記錄
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
![]() ![]() <script> function countvalueshow(myTable,colindex){ const table = document.getElementById(myTable); const rows = table.getElementsByTagName('tr'); const colCount = colindex; // 第二列的索引是1,因?yàn)樗饕龔?開(kāi)始計(jì)算 let countMap = {};
for (let i = 1; i < rows.length; i++) { // 跳過(guò)表頭 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 編輯過(guò) |
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)... |