Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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
Javascript JQuery在一个表行中获取多个表数据的每个值_Javascript_Jquery_Codeigniter - Fatal编程技术网

Javascript JQuery在一个表行中获取多个表数据的每个值

Javascript JQuery在一个表行中获取多个表数据的每个值,javascript,jquery,codeigniter,Javascript,Jquery,Codeigniter,嗨,我有一张有多行的桌子我想知道如何获取该表每行中的特定数据。在该表中,我需要获取学号数据及其附带的成绩 <tbody> <?php foreach ($class_list_view as $student) { ?> <tr> <td class="studentnumber"><?= $student->studentnumber ?></td> <td><?

嗨,我有一张有多行的桌子我想知道如何获取该表每行中的特定数据。在该表中,我需要获取学号数据及其附带的成绩

<tbody>
   <?php foreach ($class_list_view as $student) { ?>
   <tr>
      <td class="studentnumber"><?= $student->studentnumber ?></td>
      <td><?= $student->lastname ?></td>
      <td><?= $student->firstname ?></td>
      <td><?= $student->middlename ?></td>
      <td><?= $student->level ?></td>
      <td><?= $student->year ?></td>
      <td>
         <select class="custom-select grade" style="height: 20px;">
            <option selected value="">Select Grade</option>
            <option value="passed">Passed</option>
            <option value="failed">Failed</option>
         </select>
      </td>
   </tr>
   <?php } ?>
</tbody>

但是在
等级
索引中,它只取第一个。它应该在每一行中输入select的值,类似于td
studentnumber

您可以通过行而不是单元格循环

var studentnum_array = [];

$("table tbody tr").each(function(index) {
    studentnum_array.push({ 
        "studentnumber": $(this).find('td.studentnumber').text(),
        "grade": $(this).find('select.grade').val()
    });
});

console.log(studentnum_array);
如果要在单元格中循环,必须找到与相应的
studentnumber
单元格相关的
select

var studentnum_array = [];

$("table tbody td.studentnumber").each(function(index) {
    studentnum_array.push({ 
        "studentnumber": $(this).text(),
        "grade": $(this).closest('tr').find('select.grade').val()
    });
});

console.log(studentnum_array);

您可以通过行而不是单元格循环

var studentnum_array = [];

$("table tbody tr").each(function(index) {
    studentnum_array.push({ 
        "studentnumber": $(this).find('td.studentnumber').text(),
        "grade": $(this).find('select.grade').val()
    });
});

console.log(studentnum_array);
如果要在单元格中循环,必须找到与相应的
studentnumber
单元格相关的
select

var studentnum_array = [];

$("table tbody td.studentnumber").each(function(index) {
    studentnum_array.push({ 
        "studentnumber": $(this).text(),
        "grade": $(this).closest('tr').find('select.grade').val()
    });
});

console.log(studentnum_array);

由于您已经在每个
td
中循环,因此您需要找到它所包含的
tr
,然后查找
选择

 $("table tbody tr td.studentnumber").each(function (index) {
            var grade = $(this).closest('tr').find('select.grade').val();
            studentnum_array.push( {"studentnumber": $(this).text(), "grade": grade } );
        });

         console.log( studentnum_array );

由于您已经在每个
td
中循环,因此您需要找到它所包含的
tr
,然后查找
选择

 $("table tbody tr td.studentnumber").each(function (index) {
            var grade = $(this).closest('tr').find('select.grade').val();
            studentnum_array.push( {"studentnumber": $(this).text(), "grade": grade } );
        });

         console.log( studentnum_array );