我有 1 个输入类型字段...如果我更改了值,它将乘以循环中的值...这是示例...
<input type='number' id='values' name='values' onkeyup='multiplied()'>
<?php
foreach($data as $value)
{
$no = 1;
echo "<input type='number' class='form-control value' id='value' name='value' readonly value=".$value['value'].">";
echo "<input type='number' class='form-control' id='total' name='total' readonly >";
$no++;
}
?>
function multiplied()
{
var values = $('#values').val();
var value = $('.value').val();
total = values * value;
$('#total').val(total)
}
当我更改 id='values'
的值时,如何动态乘以值
谢谢,如有帮助,我们将不胜感激
最佳答案
您可以使用 jquery on
函数。
$(document).on('change', '#values', function() {
var values = $("#values").val();
$(".value").each(function(index, element){
values *= element.value;
$(this).next('input#total').val(values);
});
});
关于javascript - 使用 Jquery 在循环内动态乘以值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46619784/