我几天前编写了该代码,一切正常。我今天重写只是为了得到一些练习,现在我得到“无法读取未定义的属性‘值’”。我花了很多时间试图找出我哪里出错了,以至于我看不到树的木头。如果这听起来像是一个初学者的问题,那是因为我就是其中之一。
var btn = document.getElementById("btn");
const input = document.getElementById("input");
var elUlList = document.getElementById("uList");
function createListItems() {
var inputValue = input.value;
var newLi = document.createElement("li");
var input = document.createElement("input");
input.type = "checkbox";
var newText = document.createTextNode(inputVale);
newLi.appendChild(input);
newLi.appendChild(newText);
elUlList.appendChild(newLi);
}
btn.addEventListener("click", createListItems, false);
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>todoList practice</title>
</head>
<body>
<h1>My to do list</h1>
<input id="input" type="text" name="" value="">
<button id="btn" type="click" name="button">add item</button>
<ul id="uList"></ul>
<script src="index.js" type="text/javascript"></script>
</body>
</html>