我想知道爲什麼我的pageCounter
在頁面對象(見下文)被視爲一個字符串而不是int? 爲什麼javascript不解釋變量並將變量的名稱用作文字字符串?對象的javascript索引是字符串,而不是int
for (var i in stories){
//reset the counter when it hits the number of stories per page
if (counter >= divsByPage) {
counter = 1;
pageCounter++;
}
//turn all the stories off
//stories[i].style.display = "none";
//insert a new story under a page array
pages.push({pageCounter:stories[i]});
counter++;
}
console.log(pages[1]);
輸出Object { pageCounter=[1]}
。
它應該輸出什麼? – 2012-07-05 12:52:18
提供更多信息! – Amberlamps 2012-07-05 12:52:44
是什麼讓你覺得它是一個字符串? – Utkanos 2012-07-05 12:52:46