0
这是我的代码:无法访问一个全局变量
function Todo(id, task, who, dueDate) {
this.id = id;
this.task = task;
this.who = who;
this.dueDate = dueDate;
this.done = false;
}
var todos = new Array();
window.onload = init;
function init() {
var submitButton = document.getElementById("submit");
submitButton.onclick = getFormData;
var searchButton = document.getElementById("button");
searchButton.onclick = search;
}
//function to add todo items to the todos array
function search() {
for (var i = 0; i < todos.legnth; i++) {
var todoObj = todos[i];
console.log(todoObj[0]);
}
}
这不是我的所有代码,但最后的功能就是我有麻烦。我似乎无法访问全球待办事项数组。我试过将它作为参数传递给搜索函数。我已经尝试过,即使我做了< window.todos.length。我将不胜感激任何帮助。
尝试改变legnth长度。 – 2013-02-20 18:52:13