JS如何對(duì)比一個(gè)table指定的兩列的數(shù)據(jù)是否相同
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
![]() ![]() function compareColumns(tableId, colIndex1, colIndex2) { var table = document.getElementById(tableId); var rows = table.rows; var isSame = true;
for (var i = 1; i < rows.length; i++) { // 從1開(kāi)始,跳過(guò)表頭 var cell1 = rows[i].cells[colIndex1].innerText; var cell2 = rows[i].cells[colIndex2].innerText; if (cell1 !== cell2) { isSame = false; break; } }
return isSame; }
// 使用示例 var tableId = 'myTable'; // 你的表格ID var colIndex1 = 0; // 第一列的索引,從0開(kāi)始計(jì)數(shù) var colIndex2 = 1; // 第二列的索引,從0開(kāi)始計(jì)數(shù) console.log(compareColumns(tableId, colIndex1, colIndex2)); // 輸出比較結(jié)果 ?該文章在 2025/7/29 17:30:56 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |