这是我的 laravel
View 代码。在这里,我试图增加计数器值(即,value =“0/5”)。我在模式内有输入字段,当单击模型内的保存按钮时,该值应根据填充的输入字段递增。即(1/5..2/5..)
我尝试增加这些计数器值。但它显示NaN
var val;
$("input").click(function() {
val = $('#counter').val();
val++;
$('#counter').prop('value', val)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="panel-title pull-left">
<i class="fa fa-check-circle" style="font-size:20px;color:lightgreen">
</i> Price,stock and Shipping Information<input type="submit" id="counter" value="0/5" style="background-color: transparent; border:none">
</div>
最佳答案
<script type="text/javascript">
$("input").click(function() {
let val = parseInt($('#counter').val().split('/')[0]);
$('#counter').prop('value', `${++val}/5`);
});
</script>
关于javascript - 当输入字段被填充时如何增加计数器值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45705312/