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 編輯過 |
關鍵字查詢
相關文章
正在查詢... |