早上,我有一个问题,使用jQuery添加一些总计.
我将以下内容传递给了...
但是我得到以下结果......
subTotal = 600
productShipping = 4.05
orderTotal = 4.05600
$.each(result, function (index, res) {
var price = 600.00; //res.productPrice;
var subTotal = res.itemQty * price;
var orderTotal = res.productShipping + subTotal;
new_record = "<tr>" +
"<td class=\"totals\">Sub Total</td>" +
"<td>£" + subTotal + "</td>" +
"</tr>" +
"<tr>" +
"<td class=\"totals\">Shipping</td>" +
"<td>£" + res.productShipping + "</td>" +
"</tr>" +
"<tr>" +
"<td class=\"totals\">Order Total</td>" +
"<td>£" + orderTotal + "</td>" +
"</tr>";
$('#orderTotals').append(new_record);
Run Code Online (Sandbox Code Playgroud)
我觉得我的jQuery可能会出现一些问题,但是我可以解决这些问题.有人可以说明我出错的地方.
res是我在webservice调用中使用的响应.
非常感谢.
+将连接字符串以及将数字相加.当你得到连接时,我们可以假设这res.productShipping是一个字符串.
因此在添加之前将其解析为浮点数:
var orderTotal = parseFloat(res.productShipping) + subTotal;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
748 次 |
| 最近记录: |