javascript - 无法访问全局变量

标签 javascript character-encoding error-handling

这是我的代码:

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]);
    }
} 

这不是我的全部代码,但是最后一个功能是我遇到麻烦的地方。我似乎无法访问全局todos数组。我尝试将其作为参数传递给搜索功能。我什至尝试做我

最佳答案

问题是您有错字。

更换

todos.legnth


todos.length

关于javascript - 无法访问全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14987647/

相关文章:

javascript - ExtJS 6 - 隐藏组件时停止事件委托(delegate)?

javascript - 如何杀死子进程并允许父进程继续

javascript - CSS 或 jQuery 问题 : Website not behaving correctly

php - MySQL 字符集和 PHP

c++ - 跨平台错误信息

javascript - 递归函数返回空数组

http - tomcat的字符编码问题

java - 如何使用GBK编码将汉字写入文本文件?

android - map 中的翻新+ RX错误处理

haskell - 错误处理和单子(monad)?