Javascript Jquery-运行插件转换为USD后出现NaN错误$
这是我的建议 我有一个函数,它做的是quantity*system=grouptotal 我现在的问题是这个。我有一个插件(autoNumeric),可以将Javascript Jquery-运行插件转换为USD后出现NaN错误$,javascript,jquery,parseint,Javascript,Jquery,Parseint,这是我的建议 我有一个函数,它做的是quantity*system=grouptotal 我现在的问题是这个。我有一个插件(autoNumeric),可以将.grouptotal转换成美元。但是,当我双击它进行转换时,我的#subtotal将从一个数字变为NaN。我试着把parseInt放在我能想到的每一个地方,但在插件运行后,它总是恢复为NaN。在运行插件之前,#小计是可以的,但它们不是我需要的美元金额 我更改了sum+=+$(this.val()tosum+=+parseInt($(this
.grouptotal
转换成美元。但是,当我双击它进行转换时,我的#subtotal
将从一个数字变为NaN。我试着把parseInt放在我能想到的每一个地方,但在插件运行后,它总是恢复为NaN。在运行插件之前,#小计
是可以的,但它们不是我需要的美元金额
我更改了sum+=+$(this.val()
tosum+=+parseInt($(this.val())|0
但它在#subtotal
中只返回0
在我运行插件转换为$USD后,如何获取#subtotal
以仅从.grouptotal
中提取数字
我希望这是有意义的。使用JavaScript,您可以通过以下方式利用正则表达式:
$(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);
});
“45.00美元”是您的小计
这是找到的什么是
$(This).val()
返回的?它返回的是.grouptotal的总数
我有这个,因为一旦我单击克隆按钮,我希望所有的.grouptotal
都加到#小计
'$45.00'.match(/\d+/)[0]