问题
- 我需要使用纯javascript创建发票
- 输入(复选框(具有ID和值
<input type="checkbox" id="2Tier" value="950"/>
- 当用户单击$("input[type=checkbox]"(时,$(this(获取id和值,并将它们设置为$selectedWeddingCake和$price,然后将它们作为数组传递
$selectedWeddingCake = [$weddingCake, $price, $total];
- 然后将此列表推送到发票列表中
$ListItem.push($selectedWeddingCake);
现在我的问题是,我需要创建一个显示所有选定蛋糕的发票。
当我调用for for循环只显示一个项目时,它会挂起
我的for循环
for (i = 0; i <= $ListItem.length; i += 1) {
for (j = 0; i <= $selectedWeddingCake.length; j += 1) {
document.getElementById("demo").innerHTML = "<br>Item: " + $selectedWeddingCake[i] + "<br>Price: " + $selectedWeddingCake[i] + "<br>Total: " + $selectedWeddingCake[i];
}
}
ListItem[0]-->selectedWeddingCake[$weddingCake, $price, $total];
所需回路输出
The selected Cake is $weddingCake
The price is $price
The Total is $total
您没有更改第二个索引中的字母:
for (i = 0; i <= $ListItem.length; i += 1) {
for (j = 0; j <= $selectedWeddingCake.length; j += 1) {
document.getElementById("demo").innerHTML = "<br>Item: " + $selectedWeddingCake[i] + "<br>Price: " + $selectedWeddingCake[i] + "<br>Total: " + $selectedWeddingCake[i];
}
}
条件是j <= $selectedWeddingCake.length;
,而不是i <= $selectedWeddingCake.length;
干杯