2017-04-11 55 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

相关问题