选中复选框时如何获得总分?

时间:2018-10-17 22:27:21

标签: ajax laravel-5.4

我在违规表中有score字段。而且我有很多复选框。当我选中thed chechboxs时,总分数是用ajax收集的。

<div id="collapse6" class="panel-collapse collapse">
    <div class="panel-body">
        <div class="table-responsive">
            <table class="table table-bordered">
                @foreach($infractions as $infraction)
                    <tr>
                        <th>{{ $infraction->title }}</th>
                        <td>
                            <input type="hidden" name="infractions[{{ $infraction->id }}]" value="0" >
                            <input type="checkbox" value="1" onclick="{{ $infraction->score }}" name="infractions[{{ $infraction->id }}]" data-toggle="toggle">
                        </td>
                    </tr>
                @endforeach
            </table>
        </div>
        <div class="text-right"> Totlal
            <span id="total">

            </span>
        </div>
    </div>
</div>

infractions table

Ajax

function scorePlus (id)
{
    // var value = parseInt(document.getElementById('num'+id).value, 10);
    value = isNaN(value) ? 0 : value;
    value++;
    document.getElementById('total').value = value;
}

0 个答案:

没有答案