Jquery根据另一个单元格的状态检索单元格值

标签 jquery html-table css-selectors cells

我需要一些帮助来选择 GridView 中的单元格。我有一个这样的表:

<table>
<tr>
<th>CheckBox</th>
<th>Customer ID</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr>
<td>CheckBox</td>
<td>1</td>
<td>Joe</td>
<td>Blogs</td>
</tr>
<tr>
<td>CheckBox</td>
<td>2</td>
<td>Chris</td>
<td>White</td>
</tr>
</table>

我需要选择当前选中的行的 ID 单元格。你会怎么做?

我进行了搜索,但似乎找不到类似上述的内容。

最佳答案

$(":checkbox").click(function(){
   if(this.checked){
       var id =  $(this).parent().next().text();       
       // assuming your second column has id you're looking for [customer id]
   }
});

wokring demo

关于Jquery根据另一个单元格的状态检索单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4387526/

相关文章:

javascript - 为每个第 2、5、8、11 等类元素添加边距

javascript - 滚动我自己的工具提示,Firefox 抛出未捕获的异常

php - jQuery Masonry 追加与无限滚动重叠

html - 头部固定的div页眉/表格/div页脚结构?

css - 如何固定 html 表中的标题,其中包含带有行跨度和 coll-span 的多行标题

java - 如何使用xpath获取以下文本名称?

jquery - 在 React-pivottable 中渲染 jquery 数据表

javascript - 使用Javascript动态更改html元素id

HTML 表格 Colspan

css - 防止滚动 :target selector?