I have a table 'mytable' that looks like:
112014-11-06 18:49:26MESSAGEMATCH5NO MATCHNO MATCHI 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()
How to do this?
解决方案
You were pretty close but consider what this is in the context of map().
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();
});