Javascript 输入值 returns 未定义(待办事项列表程序)

Javascript Input value returns undefined (To do list program)

在过去的一天里,我一直在用头撞墙,我就是无法让它工作 每次我尝试创建一个待办事项列表时,它 returns 未定义而且我似乎无法检测到代码出了什么问题 我还在学习中所以请放轻松

function addToList() {
  var item = document.getElementById("candidate").Value;
  var text = document.createTextNode(item);
  var li = document.createElement("li");

  li.appendChild(text);
  document.getElementById("toDoList").appendChild(li);
}
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" href="/css/style.css" />
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <section>
    <div class="container">
      <div class="userToDoList">
        <input id="candidate" class="userInput" type="text" placeholder="New List..." />
        <button onclick="addToList()">Add</button>
      </div>
      <div class="addedLists">
        <ul id="toDoList"></ul>
      </div>
    </div>
  </section>
</body>
<script src="JS/Script.js"></script>

</html>

这一定很令人沮丧。 value.

使用大写 V

.Value 是无效的 属性。您正在寻找 .value

function addToList() {
  var item = document.getElementById("candidate").value;
  var text = document.createTextNode(item);
  var li = document.createElement("li");

  li.appendChild(text);
  document.getElementById("toDoList").appendChild(li);
}
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" href="/css/style.css" />
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <section>
    <div class="container">
      <div class="userToDoList">
        <input id="candidate" class="userInput" type="text" placeholder="New List..." />
        <button onclick="addToList()">Add</button>
      </div>
      <div class="addedLists">
        <ul id="toDoList"></ul>
      </div>
    </div>
  </section>
</body>
<script src="JS/Script.js"></script>

</html>