[英]how to get the max value from an input of having same class name using jquery
[英]How to get the max value of a numeric input from jQuery function done on a class
我有一个由 PHP 循环创建的输入,所以我想根据 php 值给每个输入一个与触摸旋转不同的最大值
刀片.php 代码:
<tbody>
@foreach ($Ch as $chemical)
<tr>
<td>{{ $chemical->id }}</td>
<td>{{ $chemical->categorie->name }}</td>
<td>{{ $chemical->model }}</td>
<td>{{ $chemical->serial_number }}</td>
<td>{{ $chemical->unit_price }} {{ $chemical->contract->currency->symbol }}</td>
<td>{{ $chemical->weight }}</td>
<td>
@php
$sum = 0;
foreach ($chemical->recieved_quantity as $rq) {
$sum += $rq->quantity;
}
@endphp
{{ $sum }}
</td>
<td>{{ $chemical->weight - $sum }}</td>
<**td><input class="ts" id="remain_{{ $chemical->id }}" name="remain_{{ $chemical->id }}" type="number" max="{{ $chemical->weight - $sum }}">
</td>**
</tr>
@endforeach
</tbody>
<script>
$('.ts').TouchSpin({
min: 0,
max: $('.ts').attr("max"),
step: 0.1,
decimals: 2,
boostat: 5,
maxboostedstep: 10,
});
</script>
您可以使用 jQuery 的.each()
方法遍历.ts
class 选择器的每个实例,并根据该特定输入实例的参数应用 TouchSpin。
<script>
$('.ts').each(function() {
$(this).TouchSpin({
min: 0,
max: $(this).attr("max"),
step: 0.1,
decimals: 2,
boostat: 5,
maxboostedstep: 10,
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.