[英]How to get checkbox state for each row in table using jQuery?
I am trying to get the state of a checkbox in each row within a table, I'm succesfully retrieving one of the values of the columns from the table, but when it comes to the column that holds the checkboxes elements, I cannot get the state. 我正在尝试获取表中每一行中复选框的状态,我正在从表中成功检索列的值之一,但是当涉及到包含复选框元素的列时,我无法获取州。
Here is the code I am using to iterate through the table for those rows selected: 这是我用来遍历表中所选行的代码:
$.each($("input[name='query']:checked"), function () {
var data = $(this).parents('tr:eq(0)');
var Name = $(data).find('td:eq(1)').text();
var Value = $(data).find('td:eq(2)'); //This is the checkbox column
console.log('Name: ' + Name + ' - Value: ' + Value );
});
And here is one sceenshot of the table itself: 这是桌子本身的一个画面:
The catch here is, if the users selects a row (ticks the checkbox in the first column) and then tries to save the changes, I need to get the value in the Name column and then the state of the checkbox in the Value column. 这里的问题是,如果用户选择一行(选中第一列中的复选框),然后尝试保存更改,则需要在“ 名称”列中获取值,然后在“ 值”列中获取复选框的状态。
Finally, here is what the console is printing using the code mentioned above: 最后,这是控制台使用上述代码打印的内容:
Change 更改
var Value = $(data).find('td:eq(2)');
to 至
var Value = $(data).find('td:eq(2) input').prop("checked");
or 要么
var Value = $(data).find('td:eq(2) input').is( ":checked" )
You have to find checkbox
in column and check for checked
property 您必须在列中找到
checkbox
并检查checked
属性
Change 更改
var Value = $(data).find('td:eq(2)');
to 至
var Value = $(data).find('td:eq(2)').find("input[type='checkbox']").prop("checked");
or 要么
var Value = $(data).find('td:eq(2) input').prop("checked");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.