我有一个encouragements
表,在数据库中有2个字段unit_score' and
max_score`。并且我正在开发一个非常简单的计分系统,并且作为概念证明,我有一个带有laravel定义变量的div,当单击按钮时,该变量应该增加1。到目前为止,我的工作正常,但是只有一次。。。单击按钮后,为什么投票价值没有继续上涨?
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered">
@foreach($encouragements as $encouragement)
<tr>
<th class="translate">{{ $encouragement->title }}</th>
<td>
<div class="input-group">
<input type="text" min="{{ $encouragement->unit_score }}" max="{{ $encouragement->max_score }}" id="num{{$encouragement->id}}" value="0" class="form-control col-sm-1 translate" name="encouragement[{{ $encouragement->id }}]">
<div class="input-group-btn">
<input type="button" onclick="incrementValue({{$encouragement->id}})" class="btn btn-warning" value="Add">
</div>
</div>
</td>
</tr>
@endforeach
</table>
</div>
<div class="text-right">Sum:
<span id="sum" class="translate">0</span>
</div>
</div>
<script>
function incrementValue(id)
{
var value = parseInt(document.getElementById('num'+id).value, 10);
value = isNaN(value) ? 0 : value;
value++;
document.getElementById('num'+id).value = value;
values = value + value;
document.getElementById('sum').innerHTML = values;
}
</script>
答案 0 :(得分:0)
将您的JS函数放在<script>
标记内。