2013-01-02 44 views
-2

我有測驗結果表格,表格中有等級單元格。顯示錶格單元格的平均值和總和

實施例(細胞級是在while循環和數字與如果檢查其他細胞後出現):

<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> 

非常感謝!!

+2

的問題不明確。什麼是你的HTML結構和你試圖獲取單元格數據的JavaScript代碼是什麼? – halilb

+0

我在表格單元格中有一些數字,我想在其他兩個單元格中顯示這些數字的平均值和數量。我是新的,我不知道如何用JavaScript做到這一點..例如​​的名稱是級顯示我在一個單元格中的細胞等級數的計數 –

+2

請編輯問題併發布實際的HTML,而不僅僅是一個描述。 – Archer

回答

1

看到這個嘖嘖http://www.amitpatil.me/table-manipulation-with-jquery/什麼,你可能正在尋找在上述頁面即第五點中提到「5)從特定列的TD找到所有的價值觀」

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

好,非常感謝。我想得到的值和一些函數來顯示平均值和計數..我有點困惑,因爲我是新的 –

+0

一旦你得到所有的價值觀結合所有他們+(確保你將變量包裝在「parseInt」 ),我想我不必解釋你如何計算加法和平均值是什麼? –

+0

我是新的JavaScript - jqeury和我需要幫助的一切..;)我正在尋找谷歌如何做到這一點 –

相關問題