js获取table第一行包含某个字符的列索引
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
![]() ![]() function getColumnIndexByChar(tableId, char) { const table = document.getElementById(tableId); if (!table) return -1; const firstRow = table.rows[0]; if (!firstRow) return -1; for (let i = 0; i < firstRow.cells.length; i++) { if (firstRow.cells[i].textContent.includes(char)) { return i; // 返回包含该字符的列索引 } } return -1; // 未找到包含该字符的列 } // 使用示例 const index = getColumnIndexByChar('myTable', '目标字符'); console.log(index); 该文章在 2025/7/24 11:11:12 编辑过 |
关键字查询
相关文章
正在查询... |