【问题标题】:Jquery addition instead of conacatinationJquery添加而不是conacatination
【发布时间】:2017-06-03 08:15:16
【问题描述】:

如果特殊佣金有任何值,我想添加佣金,否则我想将佣金默认设置为 2%%,如果用户将该字段留空,当我没有输入任何值时,计算是正确的,但当我输入任何值说 100 然后将该值连接到佣金而不是加法 请告诉我我的代码中的错误是什么?

这是我的功能:

$('body').delegate('.quantity,.price,.discount,.spl', 'keyup', function () {
        var tr = $(this).parent().parent();

        var qty = tr.find('.quantity').val();
        var price = tr.find('.price').val();

         var special_commision = 2/100; 


         if($('.spl').val()){
            var special_commision = parseInt($('.spl').val()) +  special_commision ;
         }

        var dis = tr.find('.discount').val();
        var amt = (qty * price) - (qty * price * dis) / 100;

        cal_spl = amt*special_commision;
        tr.find('.amount').val(amt);
        tr.find('.sm').val(cal_spl);


        total();
    });

【问题讨论】:

    标签: jquery addition


    【解决方案1】:
    $('body').delegate('.quantity,.price,.discount,.spl', 'keyup', function () {
        var tr = $(this).parent().parent();
    
        var qty =parseInt(tr.find('.quantity').val());
        var price = parseInt(tr.find('.price').val());
    
         var special_commision = 2/100; 
    
    
         if($('.spl').val()){
            var special_commision = parseInt($('.spl').val()) +  special_commision ;
         }
    
        var dis = parseInt(tr.find('.discount').val());
        var amt = (qty * price) - (qty * price * dis) / 100;
    
        cal_spl = amt*special_commision;
        tr.find('.amount').val(amt);
        tr.find('.sm').val(cal_spl);
    
    
        total();
    });
    

    parseInt() 你的 tr 标签值。

    【讨论】:

      猜你喜欢
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多