[英]How to get value of table cell with jquery from checkbox using absolute row number
I have a table 'mytable' that looks like: 我有一个表“ mytable”,看起来像:
<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>
I want to get the value of column 4 "MESSAGE" from a row if its checked 我想从行中获取第4列“ MESSAGE”的值(如果已选中)
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()
How to do this? 这个怎么做?
You were pretty close but consider what this
is in the context of map()
. 你是相当接近,但考虑什么this
是在上下文map()
this
is the checkbox that is checked. this
是选中的复选框。 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
. 从那里可以找到最接近的tr
,然后是具有第3个基于0的索引的td
,然后获取该td
的text()
。 td
doesn't have a value
so use text
instead. td
没有value
,请改用text
。
var ids = $('table input:checked').map(function(){
return $(this).closest('tr').find('td:eq(3)').text();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.