为什么此调用将数组的其他元素存储到数组中无法正常工作?可以看出,每当我在存储过去的第一个元素后尝试单击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;
}
答案 0 :(得分:0)
当您在数组的arrMenu复制值中推送项目而不是推送全局对象时。
arrTemp = fnPopArray();
arrMenu.push(arrTemp.splice(0));
alert("After the addition " + arrMenu);
答案 1 :(得分:0)
最终,这在此处得到了解决:jquery multitype Jagged array behaving strangely
正如我所怀疑的那样,推动行为奇怪,并继续破坏我在阵列制作上的尝试。