本文介绍了Javascript将数字添加为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码将数字解释为字符串,并将它们添加为100300而不是400:

I have the following code which interprets the numbers as strings and adds them like 100300 instead of 400:

var rate = document.getElementById('pur_price').value;
var pprice = document.getElementById('pur_price').value;
var rate1 = document.getElementById('select2').value;
var refurb = 300;
document.getElementById('avg_claim_rate').value=id;
document.getElementById('amount_claim').value=pprice+refurb;

它是pprice和refurb字段,所以如果pprice = 100且refurb = 300,我希望它显示400,其中显示100300

it's the pprice and refurb field, so if pprice=100 and refurb=300, I expect it to show 400, where as at the moment it shows 100300

推荐答案

var result = +pprice + + refurb;

这篇关于Javascript将数字添加为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 05:17