dongzhan7253 2016-02-28 15:03
浏览 52
已采纳

如何使用Jquery获取多个数组并更改其相关数组键的值

This is the sample image of the output. What I want is if I change the quantity in that column its co-related total-price will change also. I want to achieve this injquery yet Im struggling.This is my current code and it still has error if i update the quantity all the total price will change which is wrong I want to only change the total price of the edited column.

var delay = (function(){
    var timer = 0;
    return function(callback, ms){
      clearTimeout (timer);
      timer = setTimeout(callback, ms);
    };
  })();

  $(".qty-mod").keyup(function(){
          var qty = $(this).val();
          delay(function(){
          var newprice = qty * totalorgprice
          $(".price-total").val(newprice);
          console.log(qty);
      }, 1000);
  });  

enter image description here

  • 写回答

1条回答 默认 最新

  • doufei0933 2016-02-28 16:29
    关注

    You've bound all .qty-mod at once, and this is good.

    But when in the keyup() function you're operating on only one .qty-mod, so should update only the corresponding .price-total.
    And currently you're explicitly updating all of them!

      $(".qty-mod").keyup(function(){
          var qty = $(this).val();
          var newprice = qty * totalorgprice;
          $(<< here should refer to the involved .price-total only >>).val(newprice);
          console.log(qty);
      });
    

    Since you didn't show your HTML code I can only guess that your data is displayed in a <table>. If so, the << here ... only >> above might be something like:

    '.price-total', $(this).closest('tr')
    

    Explained for the case you're not easy with jQuery:

      '.price-total',    // an element with class "price-total"
      $(this)            // in the context of 
        .closest('tr')   // the <tr> parent of the [$(this)] current element
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办