我有这个表结构。
<table id = "table1">
<thead>
<tr id = "header_row">
<th> <a id = "a1">ABC</a> </th>
<th> <a id = "a2">DEF</a> </th>
<th> <a id = "a3">GHI</a> </th>
<th> <a id = "a4">JKL</a> </th>
</tr>
</thead>
<tr>.....data filling up the table.....</tr>
<tr>.............</tr>
.
.
</table>
所以我想从这个表中获取值“a2”,你能告诉我该怎么做吗?谢谢!
编辑:还有很多其他<a>
<table>
页面上有标签,那么有没有办法利用id来提取呢?
最佳答案
So from this table, I want to fetch the value "a2"
您的意思是获取标题行中第二列的 ID?
试试这个
$("#header_row th a:eq(1)").attr("id")
如果您只是想根据已知a
的id
获取ABC,那么
$("#a2").html(); //or text()
关于javascript - 使用 jQuery 获取表中的列 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36710953/