\u003c!-- 使用 jQuery 获取多个表格的 TH 和 TD 值 --\u003e\n\u003cscript\u003e\n$(document).ready(function() {\n // 获取所有的 table\n var tables = $('table');\n\n // 遍历每个 table\n tables.each(function() {\n var table = $(this);\n\n // 获取所有的 th 的值\n var thValues = [];\n table.find('th').each(function() {\n thValues.push($(this).text());\n });\n\n // 获取所有的 td 的值\n var tdValues = [];\n table.find('td').each(function() {\n tdValues.push($(this).text());\n });\n\n // 输出 th 和 td 的值\n console.log('Table:', table.index());\n console.log('TH values:', thValues);\n console.log('TD values:', tdValues);\n });\n});\n\u003c/script\u003e\n\n\u003c!-- 这段代码会获取页面上所有的 table 元素,然后遍历每个 table,获取每个 table 中的 th 和 td 的值。th 的值会存储在 thValues 数组中,td 的值会存储在 tdValues 数组中。你可以根据需要对这些值进行进一步的处理。 --\u003e


原文地址: https://www.cveoy.top/t/topic/pDRw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录