为什么将数组的其他元素存储到数组中的调用无法正常工作?正如我在存储超过第一个元素后尝试单击 SHow Array 时所看到的那样,它似乎继续并覆盖了 arrMenu 的所有早期元素。
http://jsfiddle.net/MasterOfKitties/jW5Bv/96/
操作代码在这里:
function fnPopArray()
{
arrItem[0] = document.getElementById('idName').value;
arrItem[1] = document.getElementById('idType').value;
arrItem[2] = document.getElementById('idPrice').value;
arrItem[3] = document.getElementById('idCalories').value;
/*We should generate the HTML string here. */
var strHTML = "<b><p>Name:</b>" + arrItem[0]+"</p><p>Type:"+ arrItem[1]+"</p><p>Price:"+arrItem[2]+"</p><p>Calories:"+ arrItem[3]+"</p>";
document.getElementById("idResults").innerHTML = strHTML;
$("#idResults").show();
/*now we generate the ingredients string here */
var strIngHTML = "";
for(var i=0;i<arrItem[4].length;i++)
{
strIngHTML = strIngHTML + arrItem[4][i]+"<br/>";
}
strHTML = "<b>Ingredients</b><br/>"+strIngHTML;
/*We display it in the second div we have for ingredients */
document.getElementById("idIngredients").innerHTML = strHTML;
$("#idIngredients").show();
/*So we have populated and displayed the contents of our item. Now populate it into our menu object.*/
arrMenu[intMenu]=arrItem;
intMenu = intMenu+1;
}