| JS如何对比一个table指定的两列的数据是否相同
					当前位置:点晴教程→知识管理交流
					
					→『 技术文档交流 』
					
				 
  :JS如何对比一个table指定的两列的数据是否相同  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开始,跳过表头 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开始计数 var colIndex2 = 1; // 第二列的索引,从0开始计数 console.log(compareColumns(tableId, colIndex1, colIndex2)); // 输出比较结果 该文章在 2025/7/29 17:30:56 编辑过 | 关键字查询 相关文章 正在查询... |