我想知道为什么我的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