【问题标题】:How to calculate multiplication of each row and show it with jquery如何计算每行的乘法并用jquery显示
【发布时间】:2015-10-02 14:07:45
【问题描述】:

我有一个表单,我想计算类.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>

【问题讨论】:

    标签: jquery multiplication


    【解决方案1】:

    您可以使用 jQuery each 和 find 函数来做到这一点:

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

    【讨论】:

      猜你喜欢
      • 2011-03-15
      • 1970-01-01
      • 2023-03-12
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      相关资源
      最近更新 更多