显示表格单元格的平均值和总和

时间:2013-01-02 08:58:25

标签: php javascript jquery

我有测验结果的表格,在表格中有一个等级的单元格。

示例(单元格等级处于while循环中,并且在使用if检查其他单元格后显示数字):

    <table border="1">
      <tbody>
        <tr>
          <th> id </th>
          <th> question </th>
          <th> answer </th>
          <th> correct answer </th>
          <th> grade </th>


        </tr>

        <tr>

          <td> 1 </td>
          <td> question how bla bla bla</td>
          <td> bla bla answer</td>
          <td> correct answer</td>
          <td> 5 (this cell has the grade of each question)</td>
        </tr>
        <tr>

          <td> 2 </td>
          <td> question2 how bla bla bla</td>
          <td> bla bla answer2</td>
          <td> correct answer2</td>
          <td> 8 (this cell has the grade of each question)</td>
        </tr>

// in this cell i want to show me the average from td grade

<td colspan="4" align="center">average</td>
  <td><input type="text" readonly="readonly" name="Avg" /></td>      


      </tbody>
    </table>

非常感谢!!

1 个答案:

答案 0 :(得分:1)

看到这个tut http://www.amitpatil.me/table-manipulation-with-jquery/您可能正在寻找的内容在上一页的第5点提到,即&#34; 5)查找特定列的#t的所有值&#34;

$(".grid tr").each(function(i){
   colValues[i] = $('tr:nth-child('+(i+1)+')>td:nth-child(1)').html();
});