如何计算每行的乘法并用 jquery 显示

How to calculate multiplication of each row and show it with jquery

我有一个表格,我想计算字段与 class .val.unit 的乘积,并在字段中显示 class .ad-price-item 在每一行中。我怎么能用 jquery 做到这一点?

我的表单有很多行可以添加或删除:

<div class="row">
<input name="datarows[1][radif]" class="uk-form-width-large uk-text-center" value="1" type="text">
<input name="datarows[1][code]" class="uk-form-width-large" placeholder="کد کالا" type="text">
<input name="datarows[1][name]" class="uk-form-width-large" placeholder="نام کالا" type="text">
<input name="datarows[1][value]" class="uk-form-width-large val" placeholder="مقدار" type="number">
<input name="datarows[1][unit]" class="uk-form-width-large unit" placeholder="واحد" type="text">
<input name="datarows[1][unitprice]" class="uk-form-width-large ad-money" placeholder="قیمت واحد" type="text">
<input name="datarows[1][price]" class="uk-form-width-large ad-money ad-price-item" placeholder="قیمت کل" type="text">
</div>


<div class="row">
<input name="datarows[1][radif]" class="uk-form-width-large uk-text-center" value="2" type="text">
<input name="datarows[1][code]" class="uk-form-width-large" placeholder="کد کالا" type="text">
<input name="datarows[1][name]" class="uk-form-width-large" placeholder="نام کالا" type="text">
<input name="datarows[1][value]" class="uk-form-width-large val" placeholder="مقدار" type="number">
<input name="datarows[1][unit]" class="uk-form-width-large unit" placeholder="واحد" type="text">
<input name="datarows[1][unitprice]" class="uk-form-width-large ad-money" placeholder="قیمت واحد" type="text">
<input name="datarows[1][price]" class="uk-form-width-large ad-money ad-price-item" placeholder="قیمت کل" type="text">
</div>

您可以使用 jQuery each and find 函数执行此操作:

$('.row').each(function(){
    var value = $(this).find('.val').val() * $(this).find('.unit').val();
    $(this).find('.ad-price-item').val(value);
})