如何使用绝对行号从复选框获取带有jquery的表格单元格的值 [英] How to get value of table cell with jquery from checkbox using absolute row number
问题描述
我有一张'mytable'表格,如下所示:
I have a table 'mytable' that looks like:
<tr>
<td><input type="checkbox" name="check[]" value="11"></td>
<td>11</td>
<td>2014-11-06 18:49:26</td>
<td>MESSAGE</td>
<td></td>
<td>MATCH5</td>
<td>NO MATCH</td>
<td>NO MATCH</td>
</tr>
我想从行中获取第4列MESSAGE的值(如果已选中)
I want to get the value of column 4 "MESSAGE" from a row if its checked
因为你可以看到每一行都有一个带有值的复选框。但是这个值是非顺序的,所以我不能只使用复选框值(我已经得到了
as you can see each row begins with a checkbox which have a value. however the value is non-sequential so I can't just go with the checkbox value (which I have been getting with
var IDs = $('input:checked').map(function(){
return $(this).val();
}).get();)
我需要一些计算表行的方法然后我可以使用类似的东西:
I need some way of counting table rows then I can use something like:
var id= $("#myTable tr").eq(ID).find('td').eq(4).val()
怎么做?
推荐答案
你非常接近,但考虑这个
是在 map()
的上下文中。
You were pretty close but consider what this
is in the context of map()
.
此
是选中的复选框。从那里你可以找到最接近的 tr
然后使用第3个基于0的索引找到 td
,然后得到 text()
中的 td
。 td
没有值
所以请改用 text
。
this
is the checkbox that is checked. From there you can find the closest tr
and then the td
with the 3rd 0-based index, and then get the text()
of that td
. td
doesn't have a value
so use text
instead.
var ids = $('table input:checked').map(function(){
return $(this).closest('tr').find('td:eq(3)').text();
});
这篇关于如何使用绝对行号从复选框获取带有jquery的表格单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!