简体   繁体   English

如何使用绝对行号从复选框中使用jQuery获取表单元格的值

[英]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 ,然后获取该tdtext() 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.

相关问题 使用 Jquery 从表格单元格中获取复选框的值 - Getting the value of checkbox from the table cell using Jquery 如何在行单击时使用 jquery 获取表格单元格值并将值显示到另一个表格? - How to get table cell value using jquery on row click and show the value to another table? 如何获取表格行单元格内的复选框 - How to get checkbox inside table row cell 如何在keyup事件上使用Jquery获取动态生成的表的单元格的行索引号? - How to get the row index number of the cell of a dynamically generated table using Jquery on keyup event? 通过TD类和jQuery中单元格中的特定值从表中获取行 - Get row from a table by td class and specific value in the cell in jquery 如何使用javascript或jquery获取在表的特定行中存在的复选框和文本框值 - how to get checkbox and textbox value present in a particular row of a table using javascript or jquery 如何使用jQuery获取表中每一行的复选框状态? - How to get checkbox state for each row in table using jQuery? 在jQuery中,如何获取使用复选框选择的表的特定行的值? - In jquery how to get the values of a particular row of a table that is selected using checkbox? 获取连续表格单元格的值(JS 或 jQuery) - Get the value of table cell in a row (JS or jQuery) 如何从表格单元格按钮单击获取行号? - how to get the row number from a table cell button click?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM