我有一个表单,我要计算.val
类与.unit
的字段的乘积,并在每行中将其显示在类为.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>
最佳答案
$('.row').each(function(){
var value = $(this).find('.val').val() * $(this).find('.unit').val();
$(this).find('.ad-price-item').val(value);
})