运行插件转换为USD $

时间:2016-01-20 00:37:54

标签: javascript jquery parseint

$(document).ready(function() {
  $('#clone').click(function() {
    var target = $(this).closest('.groupcontainer');
    target.clone(true, true).insertAfter(target);
  });

  $('.input').on('input',function(){
    $(this).parent().children('.grouptotal').val($(this).val() *  
$(this).parent().children('.input2').val());
  $('.grouptotal').change();
  });

  $('.input2').on('input', function(){
    $(this).parent().children('.grouptotal').val($(this).val() * 
$(this).parent().children('.input').val());
     $('.grouptotal').change();
  });
  $('.input2').dblclick(function(){
    $(this).parent().children('.input2').autoNumeric('init', {aSign: "$ "});
  });  
  $('.grouptotal').dblclick(function(){
    $(this).parent().children('.grouptotal').autoNumeric('init', {aSign: "$ "});
  });
  $('#subtotal').dblclick(function(){
    $(this).parent().children('#subtotal').autoNumeric('init', {aSign: "$ "});
  });
  $('.reset').click(function(){
    $('.behindgroup').parent().children().find('input, textarea').val('');
  });
});  


$(document).on('change', '.grouptotal', function(){
  var sum = 0;
    $('.grouptotal').each(function(){
    sum += +$(this).val();
    });
    $('#subtotal').val(sum);
      });

这是Fiddle

我有一个可以进行数量* system = grouptotal的功能。

我现在的问题是这个。我有一个插件(autoNumeric),将.grouptotal转换为USD $。但是,当我双击它进行转换时,我的#subtotal将从数字更改为NaN。我已经尝试将parseInt放在我能想到的每个地方,但是在插件运行后它总是会恢复为NaN。在运行插件之前,#subtotal没问题,但它们不是我需要的金额。

我已将sum += +$(this).val();更改为sum += +parseInt($(this).val()) || 0;,但它最终在#subtotal中返回0。

在我运行插件转换为$ USD后,如何让#subtotal.grouptotal中提取数字?

我希望这是有道理的。

1 个答案:

答案 0 :(得分:0)

使用JavaScript,您可以通过执行以下操作来利用正则表达式:

 '$45.00'.match(/\d+/)[0]

成为45.00美元'你的小计。

找到here