2017-04-11 81 views
0

我從我的數據庫中獲取值,並在我的視圖中爲總數或平均值添加了一列 。在每一行中,它有3列 與值。在數據庫中沒有平均列,而不是 放入數據庫,我只放在我的blade.php。我怎麼可能 做到這一點在JavaScript?似乎我不知道如何開始,因爲我是 不是java的主人。從th標記中添加值並在最後一列中設置總計javascript

<tbody> 
    @foreach($card['AllGrade'] as $subject) 
    <tr> 
     <th colspan="4">{!! $subject['subject'] !!}</th> 
     <th colspan="2" >{!! $subject['term_1'] !!}</th> 
     <th colspan="2" >{!! $subject['term_2'] !!}</th> 
     <th colspan="2" >{!! $subject['term_3'] !!}</th> 
     <th colspan="2" name ="ave" id ="ave" value=""> total value here</th> 
    </tr> 
    @endforeach 
+0

在PHP中執行它有什麼問題? –

回答

0

我想你不應該像這樣的代碼,你可以使用PHP代碼中添加/平均你期待,你可以查看這裏給出的代碼result.Because。只需將此代碼添加到您的刀片文件並當然可以使用Jquery

$("tbody tr").each(function() { 
    var total = 0; 
    $(this).children('th').not(':first').not(':last').each(function() { 
     //"this" is the current element in the loop 
     var number = parseInt($(this).html()); 
     total += number; 
    }); 
    $(this).children('th').last().html(total); 
}); 
+0

通過使用PHP,我已經嘗試使用內部刀片內的PHP代碼片段,但問題是我不知道如何傳遞內部php中的html元素的值。例如foo是ID或名稱元素,並使用$ _GET ['foo'] wont甚至工作?我如何通過它? – Chee

+0

謝謝你,先生,現在非常有用,它的工作。我只是想知道如何在PHP內部傳遞html元素的值。 – Chee

+0

希望我能爲此答案投票。 – Chee

相關問題