$(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
中提取数字?
我希望这是有道理的。
答案 0 :(得分:0)