如何在javascript中添加两个js变量值

时间:2014-05-27 10:52:32

标签: javascript

这是我的代码......

function calculateAmount(plotSize,planRate){

var amount = plotSize*planRate;
var currenamount= ('#totalamount').val();
 if(currenamount=='Amount'){
currenamount=0;
}
var c = parseInt(amount) + parseInt(currenamount);
$('#totalamount').val(c);

}

我想添加varriable currenamount和amount,并将其显示在totalamount div中。

1 个答案:

答案 0 :(得分:0)

$遗漏(#totalamount),因此应将当前金额初始化为:

var currenamount= $('#totalamount').val();
                 ^^^ $ here

如评论中所述,如果totalamount是div,则可以尝试此

var currenamount= ('#totalamount').text();

并将文本设置为div的总金额:

$('#totalamount').text(c);