window.onload = function(){}

时间:2017-12-02 19:32:34

标签: javascript

我正在做一个简单的待办事项列表,其中包含有关javascript的基本知识,而不是DOM操作,只是console.log()提示符(),所以当我完成运行我的代码时,我从时间开始在控制台中给出一个看起来像这样的黄色消息(见下文),有人告诉我,解决它的一种方法是使用window.onload = function(){}但看起来它只是在我没有任何其他的时候工作选项卡在我的浏览器中打开有人可以帮帮我吗?以下是我的代码和错误。[code error



window.onload = function () {
    var todos = [];
    var input = prompt("What would you like to do?");

    while (input !== "quit") {
        if (input === "list") {
            listTodos();
        } else if (input === "new") {
            var newTodo = prompt("Enter new todo");
            todos.push(newTodo);
        } else if (input === "delete") {
            var index = prompt("Enter index of todo to delete");
            todos.splice(index, 1);
            alert("Your todo has been deleted");
        }
        input = prompt("What would you like to do?");
    }
    console.log("Ok, you quit the app");

    function listTodos() {
        todos.forEach(function (todo, i) {
            console.log(i + ": " + todo);
        });
        console.log("***********")
    }
}

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>To do list</title>
</head>

<body>
    <h1>Todo List</h1>
    <br>
    <ul>
        <li>"new"- Add a Todo</li>
        <li>"list"- View All Todos</li>
        <li>"delete"- Remove Specific Todo</li>
        <li>"quit"- Quit App</li>
    </ul>
    <script type="text/javascript" src="list.js"></script>
</body>

</html>
&#13;
&#13;
&#13;

error

0 个答案:

没有答案