【发布时间】:2017-01-13 23:53:37
【问题描述】:
我想增加 HTML 内容的数量并将它们格式化为货币,例如:“$ 12.50”。
在我的例子中,有一个价格和产品数组,代码必须访问相应的数组以选择产品,找到它的价格,如果它在 HTML 中没有值,则将值发送到HTML 标记,如果 html 标记中有 Some 值,则递增到现有值。
例子:
function(product, amount){
// search the index
var index = arrayProduct.indexOf(product);
// points the element by index
var price = arrayPrices[index];
// If the tag is empty, it sends, if there is any value in the tag, it increases
document.getElementById("idPrice").innerHTML = price;
}
【问题讨论】:
-
所以可能是一个
if语句首先从标签中获取值(或缺少值),然后在现有的最后一行之前将其添加到price? -
递增,比如用一美元?还是一分钱?还是添加的金额?
-
就像一美元和美分一样:U$ 1.50 @trincot
-
我认为您的意思是 add 而不是 increment。看我的回答。
标签: javascript html