javascript - 使用 jQuery 获取表中的列 id

标签 javascript jquery html-table

我有这个表结构。

<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")

如果您只是想根据已知aid获取ABC,那么

$("#a2").html(); //or text()

关于javascript - 使用 jQuery 获取表中的列 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36710953/

相关文章:

c# - 在 c# asp.net 中将条件 requiredFieldValidators 添加到动态创建的表单

javascript - 使用 Jquery 排列 html 表格

html - Div 中的表头组和表脚组

javascript - 如何解决在 Firefox 中使用 ViewEncapsulation.Native 加载 Angular 组件的问题

javascript - 使用 jQuery 从输入获取关联数组

jquery - 在 jQuery 中将图像 SRC 转换为背景图像

javascript - 使用 jQuery 更改单击表格行的颜色

javascript - 使用 JavaScript 读取远程 PDF 文件

javascript - 访问 <img> 标签数据

html - 表格数据在html底部有很多空间