Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在表上迭代以获取具有选中状态的复选框的值?_Jquery_Html Table_Iteration - Fatal编程技术网

Jquery 如何在表上迭代以获取具有选中状态的复选框的值?

Jquery 如何在表上迭代以获取具有选中状态的复选框的值?,jquery,html-table,iteration,Jquery,Html Table,Iteration,我必须访问并获取具有输入检查状态的行的值 <table> <thead> <tr> <th>#</th> <th>Value 1</th> <th>Value 2</th> <th>Value 3</th> </tr> </thead> <tbody> <tr> <td><input type='

我必须访问并获取具有输入检查状态的行的值

<table>
<thead>
<tr> <th>#</th> <th>Value 1</th> <th>Value 2</th> <th>Value 3</th> </tr>
</thead>
<tbody>
<tr>
  <td><input type='checkbox' name='1'></td> <td>1</td> <td>1</td> <td>1 </td>
</tr>
<tr>
  <td><input type='checkbox' name='2'></td> <td>2</td> <td>2</td> <td>2 </td>
</tr>
<tr>
  <td><input type='checkbox' name='3'></td> <td>3</td> <td>3</td> <td>3 </td>
</tr>
<tr>
  <td><input type='checkbox' name='4'></td> <td>4</td> <td>4</td> <td>4 </td>
</tr>
</tbody>

您需要将
.closest()
$(this)

工作样本:-

$(“表tbody tr输入:复选框:选中”)。每个(函数(){
log($(this.closest(“tr”).html());
});

#
值1
价值2
价值3
1.
1.
1.
2.
2.
2.
3.
3.
3.
4.
4.
4.

是否可以将此值保存在数组中并发送到另一页?@ThiagoL是。但为此,你必须提出新的问题。这很难说。您可以创建一个数组对象,迭代每个选中的tr并获得每个td值。将这些值分配给数组对象,并通过ajax请求将其发送到另一个页面
$("table tbody tr input:checkbox:checked").each(function(){
        console.log($("table tbody tr").html());
     }); 
$("table tbody tr input:checkbox:checked").each(function(){
   console.log($(this).closest("tr").html());
});